一.导入依赖
导入在中央库中的依赖方法如下
<dependency> <groupId>opensymphony</groupId> <artifactId>sitemesh</artifactId> <version>2.4.2</version> <scope>runtime</scope> </dependency>
最新版的SiteMesh2
<repositories> <repository> <id>SiteMesh</id> <name>SiteMesh Repository</name> <url>http://maven-us.nuxeo.org/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>opensymphony</groupId> <artifactId>sitemesh</artifactId> <version>2.5-atlassian-9</version> </dependency> </dependencies>
二.web.xml中添加Filter
在web.xml中添加下面这个filter
<filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
该filter可以放在其它filter后面,比如org.springframework.web.filter.CharacterEncodingFilter
三.装饰器decorator
编写装饰器JSP页面,比如
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <html> <head> <title>My Site - <decorator:title default="Welcome!" /></title> <decorator:head /> </head> <body> <decorator:body /> </body> </html>
注意<decorator:title default="Welcome!" /> <decorator:head /> <decorator:body />
四.配置文件decorators.xml
通过配置文件通知
<?xml version="1.0" encoding="UTF-8"?> <decorators defaultdir="/WEB-INF/layouts"> <!-- 不进行装饰的路径 --> <excludes> <pattern>/static/*</pattern> <pattern>/api/*</pattern> </excludes> <!-- 默认装饰器 --> <decorator name="default" page="decorator.jsp"> <pattern>/*</pattern> </decorator> <decorator name="anotherdecorator" page="decorator2.jsp"> <pattern>/site*</pattern> </decorator> <decorator name="htmldecorator" page="html.jsp"> <pattern>*.html</pattern> <pattern>*.htm</pattern> </decorator> <decorator name="none"> <!-- These files will not get decorated. --> <pattern>/none/*</pattern> </decorator> </decorators>
1.理论上SiteMesh只会搞那些MIME type为html的页面,但在配置里先exclude掉一些静态内容和Restful API的路径会更省心;
2.根据路径匹配来选用装饰器,并按照从左到右匹配的方式,*号的级别最低,比如例子中(1) /site* 或 *.html 均匹配不上时才会使用 default装饰器 ; (2)/site.html 会使用anotherdecorator装饰器;
相关推荐
SiteMesh入门学习,很好的学习总结,让你在短时间里掌握sitemesh
很简单的sitemesh入门教程,希望对大家有所帮助
sitemesh入门demo。博客 Sitemesh入门和使用笔记 对应源码
Struts 2.0提供一个Sitemesh插件,允许在Sitemesh模板中使用Struts标记。 要使用Sitemesh需要包含Freemark,Sitemesh和Sitemesh插件库文件。 配置过滤器 如果需要使用Freemark模板文件作为装饰器文件,需要在web....
sitemesh 装饰 母版
web布局框架 SiteMesh教程及SiteMesh官方文档翻译
struts2-sitemesh-plugin-2.2.1.1.jarstruts2
siteMesh demo siteMesh使用文档
sitemesh 应用 Decorator 模式,用 filter 截取 request 和 response,把页面组件 d,content,banner 结合为一个完整的视图。通常我们都是用 include 标签在每个 jsp 页面中来 断的包含各种header , ...
简单的sitemesh maven项目。亲测可用
sitemesh-3.0-alpha-2.jar
struts2-sitemesh-plugin-2.1.6.jar
sitemesh.jar包 sitemesh.jar 包sitemesh.jar 包sitemesh.jar包
spring-boot-sitemesh 源码整合
siteMesh框架搭建的一个小事列
struts2-sitemesh-plugin-2.0.8.jar
sitemesh 装饰页面技术.
201.2.0/middlegenide_1.2.0.zip/download?use_mirror=nchc 下载文件:middlegenide_1.2.0.zip (7)Sitemesh: 本书使用版本:2.2 官方网站:http://www.opensymphony.com/sitemesh/index.html 下载页面:...
SiteMesh是一个网页布局和装饰框架以及Web应用程序集成框架,可帮助创建由页面组成的网站,这些页面需要一致的外观,导航和布局方案。 SiteMesh会拦截对通过Web服务器请求的任何静态或动态生成的HTML页面的请求,...
sitemesh-2.2.1.jar