可能重复:
JSP技巧使模板更容易?
我是JSPs和Servlets的新手,我想知道是否有一种简洁的方法来创建一个布局jsp并在类似的jsp页面上重用它,比如asp.net母版页.
我用谷歌搜索,有人说使用模板 http://java.sun.com/developer/technicalArticles/javaserverpages/jsp_templates 使用jstl标签库.它说要放一个这样的标签:
<%@ taglib uri='/WEB-INF/tlds/template.tld' prefix='template' %>
Run Code Online (Sandbox Code Playgroud)
但我得到错误(因为jstl.jar和standard.jar在WEB-INF/lib /目录中).
不过有人说jstl模板根据这个
Struts OR Tiles OR ??? ...... JSP模板解决方案有问题
我很乐意帮助我了解最好的方法.
编辑:我需要的是将页面的布局拆分为内容,标题等部分,并在使用布局模板的页面中设置此部分,就像asp.net母版页一样.
Ash*_*kan 85
将以下内容放在WEB-INF/tags/genericpage.tag中
<%@tag description="Overall Page template" pageEncoding="UTF-8"%>
<%@attribute name="header" fragment="true" %>
<%@attribute name="footer" fragment="true" %>
<html>
<body>
<div id="pageheader">
<jsp:invoke fragment="header"/>
</div>
<div id="body">
<jsp:doBody/>
</div>
<div id="pagefooter">
<jsp:invoke fragment="footer"/>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
要使用它:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
<t:genericpage>
<jsp:attribute name="header">
<h1>Welcome</h1>
</jsp:attribute>
<jsp:attribute name="footer">
<p id="copyright">Copyright 1927, Future Bits When There Be Bits Inc.</p>
</jsp:attribute>
<jsp:body>
<p>Hi I'm the heart of the message</p>
</jsp:body>
</t:genericpage>
Run Code Online (Sandbox Code Playgroud)
这完全符合你的想法!
这是Will Hartung在此链接上的一个很好的答案的一部分.
| 归档时间: |
|
| 查看次数: |
93490 次 |
| 最近记录: |