现在的位置: 首页 > 综合 > 正文

icai项目开发日记(-)

2013年10月11日 ⁄ 综合 ⁄ 共 4709字 ⁄ 字号 评论关闭

  说来可笑,接到这个小项目的时候还不知道什么是icai.后来Google 了一下.ICAI--智能计算机辅助教育系统(Intelligent Computer Assisted Instruction 简称ICAI).这个项目凝聚了兴趣小组的心血.花了不少时间.现在终于成型.虽然有些功能不是很理想,但至少大家一直在努力.这个系统是学习大学本科教材<编译原理>(清华大学出版)后的我们兴趣小组的一次实践.功能主要包括:文法语言,词法分析,语法分析和中间代码生成的常规分析.偶主要负责web页面和web层的集成.在此记录一二,全当备忘.
  使用工具:eclipse+myeclipse+tomcat+sql server;
  使用框架:struts+log4+dbcp;

  一.使用tiles 

tiles的典型用法有两种.无论使用哪种方法.tiles是做为一个插件放入到struts应用中的.所以必须在struts-config.xml中插入这个插件通常的配置如下:

 

<plug-in className="org.apache.struts.tiles.TilesPlugin" >
      
<!-- Path to XML definition file -->
      
<set-property property="definitions-config"
                      value
="/WEB-INF/tiles-defs.xml" />
      
<!-- Set Module-awareness to true -->
      
<set-property property="moduleAware" 
                      value
="true" />
</plug-in>  

第一种用法是先创建一个公用layout.jsp页用来布局.然后在其中引用tiles-defs.xml文件中配置好的元素:
文件layout.jsp:

<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="white">
  
<tr>
    
<td width="24%" height="10"> </td>
    
<td width="76%" height="10"><tiles:insert attribute="header"/></td>
  
</tr>
  
<tr>
    
<td width="24%" height="100%" align="right" valign="top"><tiles:insert attribute="sidebar"/></td>
    
<td width="76%" height="100%" align="left"><div id="body"><tiles:insert attribute="content"/> </div></td>
  
</tr>
</table>
<table width="100%" border=0 align="center" cellPadding=0 cellSpacing=0 bgcolor="WHITE" margin-bottom=0>
  
<tr>
    
<td height="64"><tiles:insert attribute="footer"/> </td>
  
</tr>
</table>

文件tiles-defs.xml就像一个零件装配的工厂,通过它可以组装各种网页,这对于见面风格的统一很是方便.重用的是它可以继承已有的组件以实现复用.

<?xml version="1.0" encoding="ISO-8859-1" ?>

 
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
       "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd"
>

<tiles-definitions>
   
<definition  name="sidebar-definition"   path="/WEB-INF/tiles/common/sidebar-layout.jsp">
      
<put name="bottom" value="/WEB-INF/tiles/common/sidebar-links.jsp"/>
   
</definition>  
   
<definition  name="base-definition"  path="/WEB-INF/tiles/common/layout.jsp">
      
<put name="top-header"  value="/WEB-INF/tiles/common/top-header.jsp"/>
      
<put name="sidebar" value="sidebar-definition" type="definition"/>
      
<put name="title"  value="/WEB-INF/tiles/common/title.jsp"/>
      
<put name="header"  value="/WEB-INF/tiles/common/header.jsp"/>
      
<put name="content" value=""/>
      
<put name="footer"  value="/WEB-INF/tiles/common/footer.jsp"/>
   
</definition>
<!--
    for defaul web
-->
   
<definition  name="index-definition"   extends="base-definition">
      
<put name="content" value="/WEB-INF/tiles/default/Welcome.jsp"/>   
   
</definition>
</tiles-definitions>

当然用tiles装订的网页是不能直接在地址栏中用localhost:8080/myapp/index-definition 访问的.

访问的方法是是struts-config.xml中设置<action-mapping>属性进行访问:

<action-mappings>
    
<action path="/index"  forward="index-definition"/>
</action-mappings>

此时即可用http://localhost:8080/myapp/index.do 进行访问.

  第二种方法其实和第一种方法大同小异.思想是在每一个.jsp页面中布局装订各个元素.例如:
index.jsp

<%@ page contentType="text/html;charset=GB2312"%>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld"%>
<%@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld"%>
<%@ taglib prefix="tiles" uri="/WEB-INF/struts-tiles.tld"%>

<tiles:insert page="/tile/layout.jsp" flush="true">
    
<tiles:put name="header" value="/tile/header.jsp"/>
    
<tiles:put name="navigation" value="/tile/navigation.jsp"/>
    
<tiles:put name="product" value="/tile/adminlogin.jsp"/>
    
<tiles:put name="page" value="/tile/page.jsp" />
    
<tiles:put name="footer" value="/tile/footer.jsp"/>
</tiles:insert>

它将用到layout.jsp这个文件:

<TABLE width="100%"border="0" align="center" cellpadding="0" cellspacing="0" >
            
<TR>
                
<TD colspan="3" align="center">
                    
<tiles:insert attribute="header" />
                
</TD>
            
</TR>
            
<TR>
                
<TD colspan="3" align="right">
                    
<tiles:insert attribute="navigation" />
                
</TD>
            
</TR>
            
<TR height="100%">
                
<TD width="1%" height="1"></TD>
                
<TD width="99%" align="center">
                    
<tiles:insert attribute="product" />
                
</TD>
                
<TD width="1%"></TD>
            
</TR>
            
<TR>
                
<TD width="1%" height="1"></TD>
                
<TD width="99%" align="right">
                    
<tiles:insert attribute="page" />
                
</TD>
                
<TD width="1%"></TD>
            
</TR>
            
<TR>
                
<TD colspan="3" align="center">
                    
<tiles:insert attribute="footer" />
                
</TD>
            
</TR>
 
</TABLE>

当然这时候就可以直接在地址栏中用http://localhost:8080/myapp/index.jsp 访问了.使用tiles的好处就是可以灵活的组装网页的各个模块.是实现复用的好工具.

  

抱歉!评论已关闭.