struts2 +tiles 配置

1. web.xml配置,加入

<!-- struts2 tiles config -->
<context-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>


<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>

2. struts.xml 配置。

 <package name="com.test.action" extends="tiles-default">
        <action name="login" class="com.test.action.LoginAction">
            <exception-mapping result="usernameInvalid" exception="com.test.exception.UsernameException" />
            <exception-mapping result="passwordInvalid" exception="com.test.exception.PasswordException" />
            <!-- 
               <result name="success">/jsp/index.jsp</result>
             -->     
            
         
   <result name="success" type="tiles">mainpage</result>
            <result name="input">/jsp/login.jsp</result>
            <result name="usernameInvalid">/jsp/usernameInvalid.jsp</result>
            <result name="passwordInvalid">/jsp/passwordInvalid.jsp</result>
        </action>

3 新增布局定义文件,WEB-INF/tiles.xml

<?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
    <definition name="homepage" template="/jsp/tiles/layout.jsp">
        <put-attribute  name="title" value="Tiles tutorial homepage" /> <!--旧版本是put,不是put-attribut-->
       <put-attribute  name="header" value="/jsp/tiles/header.jsp" />
       <put-attribute  name="menu" value="/jsp/tiles/menu.jsp" />
        <put-attribute  name="body" value="/jsp/tiles/cBody.jsp" />
        <put-attribute  name="footer" value="/jsp/tiles/footer.jsp" />
    </definition>
    
    <definition name="mainpage" extends="homepage">
        <put-attribute name="body" value="Manual Transaction Input"/>        
    </definition>
    
</tiles-definitions>

4 新增TLD文件,WEB-INF/tiles-jsp.tld。在tiles-jsp.jar包中。

5. 模板layout.jsp文件。

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/tiles-jsp.tld" prefix="tiles"%>
<html>
    <head>
       <title></title>
    </head>
    <body>
       <table width="100%" height="100%" border="2" align="center">
      
           <tr>
              <td colspan="2" align="center" valign="top" width="100%" height="100px" bgcolor="#80ff80">
                  <tiles:insertAttribute name="header" />
              </td>
           </tr>
           <tr>
              <td align="center" width="150px" height="100%" bgcolor="#00ff00">
                  <tiles:insertAttribute name="menu" />
              </td>
              <td align="right" width="618px" height="100%" 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>

jar基本包(6个)
  1.commons-logging-1.0.4.jar
  2.commons-fileupload-1.2.1.jar
  3.ognl-2.6.11.jar
  4.struts2-core-2.1.6.jar
  5.xwork-2.1.2.jar
  6.freemarker-2.3.13.jar


整合tiles必须包(7个)
.struts2-tiles-plugin-2.1.6.jar
  2.tiles-api-2.0.6.jar
  3.tiles-core-2.0.6.jar
  4.tiles-jsp-2.0.6.jar
  5.commons-digester-1.8.jar
  6.commons-collections-3.2.jar
  7.commons-beanutils-1.7.0.jar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值