OS(OpenSymphony)的SiteMesh是一个用来在JSP中实现页面布局和装饰
(layout and decoration)的框架组件,能够帮助网站开发人员较容
易实现页面中动态内容和静态装饰外观的分离
SiteMesh使用方式:
①导包:
sitemesh-2.4.2.jar
struts2-sitemesh-plugin-2.2.3.jar
②web.xml中配置过滤器
org.apache.struts2.dispatcher.ActionContextCleanUp
com.opensymphony.sitemesh.webapp.SiteMeshFilter
org.apache.struts2.dispatcher.FilterDispatcher
③在WEB-INF中建立装饰器配置文件decorators.xml
<!-- defaultdir指定模板存放的文件夹 -->
<decorators defaultdir="/template">
<!-- 表示排除装饰的页面-->
<excludes>
<pattern>/login.jsp</pattern>
</excludes>
<!-- 指定具体模板 -->
<decorator name="m" page="template.jsp">
<!-- 设置需要被装饰的页面 -->
<pattern>/*</pattern>
</decorator>
<decorator name="head" page="head.jsp"></decorator>
<decorator name="menu" page="menu.jsp"></decorator>
<decorator name="foot" page="foot.jsp"></decorator>
</decorators>
④基本模板页template.jsp中引入标签
<%@ taglib prefix="sitemesh-decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%>
<%@ taglib prefix="sitemesh-page" uri="http://www.opensymphony.com/sitemesh/page" %>
模板页中基础配置
<head>
<title>
<sitemesh-decorator:title default="Mysterious page..." />
</title>
<!-- 把被装饰的页面的头信息取过来 -->
<sitemesh-decorator:head />
<body>
<sitemesh-page:applyDecorator name="header" />
<!-- 把被装饰页面的body信息提取过来显示 -->
<sitemesh-decorator:body />
<sitemesh-page:applyDecorator name="fooder" />
</body>
</html>
(layout and decoration)的框架组件,能够帮助网站开发人员较容
易实现页面中动态内容和静态装饰外观的分离
SiteMesh使用方式:
①导包:
sitemesh-2.4.2.jar
struts2-sitemesh-plugin-2.2.3.jar
②web.xml中配置过滤器
org.apache.struts2.dispatcher.ActionContextCleanUp
com.opensymphony.sitemesh.webapp.SiteMeshFilter
org.apache.struts2.dispatcher.FilterDispatcher
③在WEB-INF中建立装饰器配置文件decorators.xml
<!-- defaultdir指定模板存放的文件夹 -->
<decorators defaultdir="/template">
<!-- 表示排除装饰的页面-->
<excludes>
<pattern>/login.jsp</pattern>
</excludes>
<!-- 指定具体模板 -->
<decorator name="m" page="template.jsp">
<!-- 设置需要被装饰的页面 -->
<pattern>/*</pattern>
</decorator>
<decorator name="head" page="head.jsp"></decorator>
<decorator name="menu" page="menu.jsp"></decorator>
<decorator name="foot" page="foot.jsp"></decorator>
</decorators>
④基本模板页template.jsp中引入标签
<%@ taglib prefix="sitemesh-decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%>
<%@ taglib prefix="sitemesh-page" uri="http://www.opensymphony.com/sitemesh/page" %>
模板页中基础配置
<head>
<title>
<sitemesh-decorator:title default="Mysterious page..." />
</title>
<!-- 把被装饰的页面的头信息取过来 -->
<sitemesh-decorator:head />
<body>
<sitemesh-page:applyDecorator name="header" />
<!-- 把被装饰页面的body信息提取过来显示 -->
<sitemesh-decorator:body />
<sitemesh-page:applyDecorator name="fooder" />
</body>
</html>