9.struts1.x中tiles框架的使用
先引入標(biāo)簽:<%@taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
將模板頁面要代替的內(nèi)容用標(biāo)簽占位:<tiles:insert attribute="content"></tiles:insert>
在另外一頁面將模板頁與內(nèi)容頁整合:
<tiles:insert page="usertemplate.jsp">
<tiles:put name="content" value="zczzh.jsp"></tiles:put>
</tiles:insert>
先插入框架的插件
<!-- 使用tiles框架則要將它的插件插入,當(dāng)在頁面用tiles標(biāo)簽時,則不必要加入些插件,
??? 事實上直接使用tiles標(biāo)簽也蠻簡單,只是多了一個頁面
??? ,但是它可以使用其它的自定義action,各人所好吧。
??? 參數(shù)相注意,就這么寫-->
??? <plug-in className="org.apache.struts.tiles.TilesPlugin">
??????? <set-property property="definitions-config"
??????????? value="/WEB-INF/tiles-defs.xml" />
??????? <set-property property="definitions-parser-validate"
??????????? value="true" />
</plug-in>
? ?定義tiles配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "tiles-config_1_1.dtd" >
<component-definitions>
<!--
可以配置一個模板頁面,然后其它頁面從它來繼承,如下:
它的其中一個空位置并沒有被填充
?-->
? <definition name="template" page="/template.jsp">
? <put name="head" value="head.jsp" ></put>
? <put name="foot" value="foot.jsp" ></put>
? <put name="left" value="left.jsp" ></put>
? </definition>
? <!--
? 這個頁面繼承了模板頁面,填充了它沒有填充的地方。
? 當(dāng)然如果模板頁面已經(jīng)填充,它可以覆蓋。
?? -->
? <definition name="register" extends="template">
? <put name="content" value="content2.jsp"></put>
? </definition>
</component-definitions>
?????? 在struts的action中調(diào)用
<!-- 使用tiles,則自定義的action必須繼承ForwardAction,其它跟別的自定義action一樣,不過
??????? 它的parameter屬性用來指定tiles配置文件中definition標(biāo)簽的name,當(dāng)兩者相同時如果execute方法返回值為null,
??????? 則頁面轉(zhuǎn)向parameter指定的組合頁面。否則到相應(yīng)的頁面,蠻有用的 -->
??????? <action path="/testtiles" type="edu.yzu.action.MyTilesAction"
??????????? parameter="register">
??????????? <forward name="success" path="/index.jsp"></forward>
??????? </action>
轉(zhuǎn)載于:https://www.cnblogs.com/jinkun/archive/2010/05/03/1726456.html
總結(jié)
以上是生活随笔為你收集整理的9.struts1.x中tiles框架的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Drools规则引擎使用入门
- 下一篇: C#实现从服务器上下载DLL文件