struts2.0 整合tiles 1配置(转载后的修改)

最近作项目时,使用了struts2+tiles,可是发现使用tiles2配合struts2会出现中文乱码问题,在网上找了,也有看见其他人这样说。

于是把原来在网上找的相关文章,进行修改后使用tiles1可以正常使用,内容如下(以下是我转载后进行的修改文章):

 

1. WEB-INF/lib 下加入所需的 jar  
    commons-digester-1.6.jar
    tiles-core-2.0-20070207.130156-4.jar
    tiles-api-2.0-20070207.130156-4.jar
    struts2-tiles-plugin-2.0.6.jar
struts2-core-2.0.6.jar
xwork-2.0.1.jar
2. 以下内容添加到 web.xml
 
 
    < listener >
      < listener-class >
        org.apache.tiles.listener.TilesListener
      </ listener-class >
   </ listener >
 
 
3. WEB-INF 下添加和 tiles.tld tiles.xml 文件,其中 tiles.tld 内容为 tiles-core-2.0-20070207.130156-4.jar 包中 META_INF/tiles-core.tld 的内容。
tiles.xml 内容:
<? xml version = "1.0" encoding = "UTF-8" ?>
<! DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://jakarta.apache.org/struts/dtds/tiles-config.dtd" >
< tiles-definitions >
    < definition name = "myapp.homepage" template = "layout.jsp" >
       < put name = "title" value = "Tiles tutorial homepage" />
       < put name = "header" value = "/tiles/header.jsp" />
       < put name = "menu" value = "/tiles/menu.jsp" />
       < put name = "body" value = "/tiles/cBody.jsp" />
       < put name = "footer" value = "/tiles/footer.jsp" />
    </ definition >
</ tiles-definitions >
   
4.struts.xml 为:
<! DOCTYPE struts PUBLIC  
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
        "http://struts.apache.org/dtds/struts-2.0.dtd" >
< struts >
    < package name = "default" extends = "tiles-default" >
       <action name="go" class="com.action.MyAction">
           <!--result name="success">/next.jsp</result-->
           < result name = "success" type = "tiles" > myapp.homepage </ result >
       </ action >
       </ package >
</ struts >
红色部分根据自己项目定。注意 extends = "tiles-default"
5 创建 layout.jsp
<%@ page contentType = "text/html; charset=UTF-8" %>
<%@ taglib uri = "WEB-INF/tiles.tld " prefix = "tiles" %>
< html >
    < head >
       < title ></ title >
    </ head >
    < body >
       < table width = "768px" height = "800px" border = "2" align = "center" >
      
           < tr >
              < td colspan = "2" align = "center" valign = "top" width = "768px" height = "100px" bgcolor = "#80ff80" >
                  < tiles:insertAttribute name = "header" />
              </ td >
           </ tr >
           < tr >
              < td align = "center"  width = "150px" height = "800px" bgcolor = "#00ff00" >
                  < tiles:insertAttribute name = "menu" />
              </ td >
              < td align = "right"  width = "618px" height = "800px" bgcolor = "#ff80c0" >
                  < tiles:insertAttribute name = "body" />
              </ td >
           </ tr >
           < tr >
              < td colspan = "2" bgcolor = "#00ff40" height = "100px" >
                  < tiles:insertAttribute name = "footer" />
              </ td >
           </ tr >
       </ table >
    </ body >
</ html >
 
6. 根据
< put name = "title" value = "Tiles tutorial homepage" />
       < put name = "header" value = "/tiles/header.jsp" />
       < put name = "menu" value = "/tiles/menu.jsp" />
       < put name = "body" value = "/tiles/cBody.jsp" />
       < put name = "footer" value = "/tiles/footer.jsp" />
WebRoot 下创建 tiles 目录和相应 jsp 文件

 

 

你可能感兴趣的:(struts,header,table,action,menu,encoding)