哪种模板方法更常见?
a)生成2个静态文件header.jsp,footer.jsp,一些动态文件,例如。 index.jsp,content.jsp和using <jsp-config>
所以只要附加servlet转发页眉和页脚。
<jsp-config>
<jsp-property-group>
<url-pattern>/WEB-INF/*</url-pattern>
<include-prelude>/WEB-INF/header.jspf</include-prelude>
<include-coda>/WEB-INF/footer.jspf</include-coda>
</jsp-property-group>
</jsp-config>
@WebServlet("/index")
// ...
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
// do work
request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
}
优点:
克罗:
b)生成1个静态文件mainpage.jsp,少量动态文件并使用<jsp:include page='${pageUrl}'>
所以每当servlet转发需要添加带有site-content url的属性时
@WebServlet("/index")
// ...
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
// do work
request.setAttribute("pageUrl", "index.jsp");
request.getRequestDispatcher("/WEB-INF/mainpage.jsp").forward(request, response);
}
<%@ page ... #>
<html>
<body>
<div id="header"></div>
<div id="content">
<jsp:include page='${pageUrl}'>
</div>
<div id="footer"></div>
</body>
</html>
<%@ page ... %>
content
优点:
克罗:
c)?