可能重复: JSP技巧使模板更容易?
I我是JSPs和Servlets的新手,我想知道是否有一种简洁的方法来创建一个布局jsp并在类似的jsp页面上重用它,比如asp母版页。
I'm new to JSPs and Servlets, I'm wondering is there a neat way to create a layout jsp and reuse it on similar jsp pages, something like asp master pages.
我用Google搜索,有人说使用模板 http:// java.sun/developer/technicalArticles/javaserverpages/jsp_templates 使用jstl标记库。它说要放置这样的标签:
I googled it, some people say use templates java.sun/developer/technicalArticles/javaserverpages/jsp_templates that uses jstl tag library. It says to put a tag like this:
<%@ taglib uri='/WEB-INF/tlds/template.tld' prefix='template' %>但是我收到错误(因为jstl.jar和standard.jar在WEB-INF / lib /中目录)。
but I get error (because jstl.jar and standard.jar are in WEB-INF/lib/ directory).
然而有人说jstl模板根据这个 Struts OR Tiles OR ??? ...... JSP模板解决方案
However some say jstl template have problems according to this Struts OR Tiles OR ???...... JSP template solution
我很乐意帮助我了解最好的方法。
I would be glad to help me know the best way.
编辑:我需要的是将页面的布局拆分成内容,标题, ...并在使用布局模板的页面中设置此部件,与asp母版页完全相同。
What I need is to split page's layout into parts like content, header,... and set this parts in the page that uses the layout template, exactly like asp master page.
推荐答案Put WEB-INF / tags / genericpage.tag中的以下内容
Put the following in 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>要使用此功能:
<%@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>这完全符合你的想法!
这是Will Hartung关于此链接的精彩答案的一部分。
This was part of a great answer by Will Hartung on this link.
更多推荐
创建JSP布局模板的最佳方法是什么?
发布评论