Tiles傻瓜式入门―hajavaor―

类别:Java 点击:0 评论:0 推荐:

Tiles傻瓜式入门―hajavaor― //=========================== Author:hajavaor Email:[email protected] QQ:19843788 //=========================== 0、适用读者:了解Tag lib,使用Struts(当然了,Tiles属于Struts嘛。) 1、有一个文件,名为test.jsp。内容如下: <html><body>This is the header.</body></html> <html><body>This is the body. </body></html> <html><body>This is the footer. </body></html> 2、拆此文件为三个文件,分别为: test_header.jsp <html><body>This is the header.</body></html> test_body.jsp <html><body>This is the body.</body></html> test_footer.jsp <html><body>This is the footer.</body></html> 3、修改test.jsp文件,使用tiles标签。这便是我的第一个tiles例子了。 <tiles:insert page="test_header.jsp"/> <tiles:insert page="test_body.jsp"/> <tiles:insert page="test_footer.jsp"/> 由原来的一个文件变成了四个文件。继续看。 4、将上面的文件再换成下面两个文件: test_template.jsp,这是一个模板文件。 <html:html> <head><title></title></head> <body> <tiles:insert attribute="header"/> <tiles:insert attribute="body"/> <tiles:insert attribute="footer"/> </body> </html:html> 将test.jsp改成这样: <tiles:insert page="/test_template.jsp" flush="true"> <tiles:put name="header" value="/test_header.jsp" /> <tiles:put name="body" value="/test_body.jsp" /> <tiles:put name="footer" value="/test_footer.jsp" /> </tiles:insert> 5、再进一步修改,编辑一个tiles-defs.xml文件,内容为: <definition name="MyTilesTest" path="/test_template.jsp"> <put name="header" value="/test_header.jsp" /> <put name="body" value="/test_body.jsp" /> <put name="footer" value="/test_footer.jsp" /> </definition> 修改test.jsp文件内容为: <tiles:insert definition name="MyTilesTest" /> 就变成一句代码了,很简洁吧。 怎么样,你知道Tiles是怎么回事了吧,就算入门了,赶紧看Tiles的API吧。 本文的目的只是让你建立Tiles的概念,而具体如何使用,请看相关文档。

本文地址:http://com.8s8s.com/it/it16933.htm