`

Tiles傻瓜式入门

阅读更多
0、适用读者:了解Tag lib,使用Struts(当然了,Tiles属于Struts嘛。)
1、有一个文件,名为test.jsp。内容如下:
<</span>html><</font>body>This is the header.<</font>/body><</font>/html>
<</font>html><</font>body>This is the body. <</font>/body><</font>/html>
<</font>html><</font>body>This is the footer. <</font>/body><</font>/html>
2、拆此文件为三个文件,分别为:
test_header.jsp
<</font>html><</font>body>This is the header.<</font>/body><</font>/html>

test_body.jsp
<</font>html><</font>body>This is the body.<</font>/body><</font>/html>

test_footer.jsp
<</font>html><</font>body>This is the footer.<</font>/body><</font>/html>
3、修改test.jsp文件,使用tiles标签。这便是我的第一个tiles例子了。
page="test_header.jsp"/>
page="test_body.jsp"/>
page="test_footer.jsp"/>

由原来的一个文件变成了四个文件。继续看。
4、将上面的文件再换成下面两个文件:
test_template.jsp,这是一个模板文件。


<</font>head><</font>title><</font>/title><</font>/head>
<</font>body>
attribute="header"/>
attribute="body"/>
attribute="footer"/>
<</font>/body>


将test.jsp改成这样:
page="/test_template.jsp" flush="true">
name="header" value="/test_header.jsp" />
name="body" value="/test_body.jsp" />
name="footer" value="/test_footer.jsp" />

5、再进一步修改,编辑一个tiles-defs.xml文件,内容为:
name="MyTilesTest" path="/test_template.jsp">
name="header" value="/test_header.jsp" />
name="body" value="/test_body.jsp" />
name="footer" value="/test_footer.jsp" />


修改test.jsp文件内容为:
definition name="MyTilesTest" />

就变成一句代码了,很简洁吧。
怎么样,你知道Tiles是怎么回事了吧,就算入门了,赶紧看Tiles的API吧。
本文的目的只是让你建立Tiles的概念,而具体如何使用,请看相关文档
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics