在Struts中使用Tiles简明手册

 如果要在Struts中使用tiles,首先要保证页面可以正确引入struts-tiles.tld,即<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>。另外在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>
 <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

    //定义一个母板
    <definition name=".mainLayout" path="/common/layouts/classicLayout.jsp">
        <put name="title"  value="Sample Page Title" />
        <put name="header" value="/common/header.jsp" />
        <!--put name="menu"   value=".mainMenu" /-->
        <put name="footer" value="/common/footer.jsp" />
        <put name="body"   value="" />
    </definition>
    在classicLayout.jsp文件中如下:
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <!--%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %-->
 <%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
 <html>
   <head><title>Simple jsp page</title></head>
    <body bgcolor="#ffffff" text="#000000" link="#023264" alink="#023264" vlink="#023264">
     <table border="0" width="100%" cellspacing="5">
     <tr>
     <td colspan="2"><tiles:insert  attribute="header" /></td>
     </tr>
     <tr>
     <td width="140" valign="top">
     <!--tiles:insert attribute='menu'/-->
     </td>
     <td valign="top" align="left">
     <tiles:insert attribute='body' />
     </td>
     </tr>
     <tr>
     <td colspan="2">
     <tiles:insert attribute="footer" />
     </td>
     </tr>
     </table>
     </body>
 </html>

    //定义子板,其通过extends继承母板
    <definition name="ordertiles" extends=".mainLayout">
        <put name="body"   value="/pages/order.jsp" />
    </definition>
 //定义一个action,它是指向tiles模板的。
 <action path="/ordertiles" type="org.apache.struts.actions.ForwardAction" parameter="ordertiles"></action>
        //定义一个action,其forward path为一个包含tiles模板的action
        <action path="/editOrder" type="heroking.action.EditOrder"
   name="OrderForm" scope="request"
   validate="false">
   <forward name="success" path="/ordertiles.do"/>
  </action>
        <action path="/submitOrder" type="heroking.action.SubmitOrder"
   name="OrderForm" scope="request"
   validate="false">
   <forward name="success" path="/ordertiles.do"/>
  </action>
即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值