本文主要是介绍使用SiteMesh分割、装饰jsp页面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. 在WEB-INF下添加decorators.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/decorator/">
<!-- 不需要过滤的请求 -->
<excludes>
<!-- <pattern>/static/*</pattern> -->
<!-- <pattern>/resources/*</pattern> -->
</excludes>
<!-- 定义装饰器要过滤的页面 -->
<decorator name="default" page="default.jsp">
<pattern>/index</pattern>
<pattern>/home</pattern>
</decorator>
</decorators>
2.web.xml中添加过滤器:
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.添加jar包:
sitemesh-2.4.2.jar
4.在WEB-INF/decorator/下新建装饰页面default.jsp
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="sitemesh"
uri="http://www.opensymphony.com/sitemesh/decorator"%>
<%@include file="../subPages/css.jsp"%>
<body>
<%@include file="../subPages/top.jsp"%>
<%@include file="../subPages/search.jsp"%>
<sitemesh:body />
<%@include file="../subPages/footer.jsp"%>
</body>
</html>
此时访问/index,该页面将采用default.jsp 装饰(将/index页面的body部分替换<sitemesh:body />,生成一个新的页面)
这篇关于使用SiteMesh分割、装饰jsp页面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!