SiteMesh 2.X版本的简单使用
1. SiteMesh的简介
2. SiteMesh的工作原理
SiteMesh是基于Servlet的filter的,即过滤流。它是通过截取reponse,并进行装饰后再交付给客户。
其中涉及到两个名词: 装饰页面(decorator page)和 “被装饰页面(Content page)" , 即 SiteMesh通过对Content Page的装饰,最终得到页面布局和外观一直的页面,
并返回给客户
运行环境需要:servlet2.3 , JDK1.4 以上。
2.1 正常模式下的web访问流程
2.2 加入SiteMesh装饰的web访问流程
2.2 SiteMesh配置文件
SiteMesh通过sitemesh.xml 和 decorators.xml配置文件来管理装饰页面以及高级属性的配置。
这两个文件都放置在/WEB-INF下
3. 搭建SiteMesh环境
3.1 准备资源
以上该链接可以获得siteMesh2.4.jar, sitemesh-page.tld , sitemesh-decorator.tld 这个三个必要文件
将jar包复制进/WEB-INF/lib目录下, 两个tld文件导入/WEB-INF下即可
在web.xml中加入siteMesh的filter和taglib
<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> <!-- not required for containers that fully support JSP 1.2 --> <taglib> <taglib-uri>sitemesh-page</taglib-uri> <taglib-location>/WEB-INF/lib/sitemesh-page.tld</taglib-location> </taglib> <taglib> <taglib-uri>sitemesh-decorator</taglib-uri> <taglib-location>/WEB-INF/lib/sitemesh-decorator.tld</taglib-location> </taglib>
3.2 建立decorators.xml
在/WEB-INF下创建decorators.xml文件,siteMesh通过该文件来获知"装饰页面"和"被装饰页面"的映射
decorators.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- 默认目录 --> <decorators defaultdir="/decorators"> <!-- 缺省装饰页 --> <decorator name="main" page="main.jsp"> <pattern>/*</pattern> </decorator> <!-- 自定义装饰页,我们下面实例就是这部分起作用 --> <decorator name="mai" page="mai.jsp"> <pattern>/mai.html</pattern> </decorator> <!-- 只装饰一个页面也可用这种方式定义 --> <decorator name="panel" page="panel.jsp"/> <!-- 装饰velocity模板 --> <decorator name="velocity" page="velocity.vm"> <pattern>/velocity.html</pattern> </decorator> <!-- 装饰freeMarker模板 --> <decorator name="freemarker" page="freemarker.ftl"> <pattern>/freemarker.html</pattern> </decorator> <decorator name="test" page="test.jsp"> <pattern>/agent.jsp</pattern> </decorator> </decorators>
3.3 装饰页的创建
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> /*这里导入了SiteMesh的标签库 */ <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> OK,there is a decorator begin!<hr /> /*这里的意思是,被装饰页的title内容将会在这里插入 */ <decorator:title></decorator:title> </head> <body> /*被修饰页的body内容将在这里插入 <decorator:body></decorator:body> <hr />Yse,there is a decorator end ! </body> </html>
3.4 被修饰页的创建
在web目录(或webContent)下创建mai.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> this is the Content Page !!! </body> </html>
3.5 使用tomcat进行示例运行,访问http://localhost:8080/{your project name}/mai.html , 运行结果如下:
转自:http://www.cnblogs.com/mailingfeng/archive/2012/02/20/2296041.html
相关推荐
SiteMesh教程.pdf
SiteMesh教程.doc
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.jar包 sitemesh.jar 包sitemesh.jar 包sitemesh.jar包
sitemesh-2.4.1.jar sitemesh-2.4.1.jar sitemesh-2.4.1.jar sitemesh-2.4.1.jar sitemesh-2.4.1.jar sitemesh-2.4.1.jar
sitemesh-2.2.1.jar
sitemesh-2.3.jar
用于在SSH2工程中使用sitemesh-2.4.jar 包;
sitemesh-2.2.1.jarsitemesh-2.2.1.jarsitemesh-2.2.1.jar
sitemesh-3.0-alpha-2.jar
sitemesh-2.2.1.rar sitemesh-2.2.1.rar sitemesh-2.2.1.rar
struts2-sitemesh-plugin-2.1.8.1.jar
sitemesh 装饰页面技术.
Struts 2.0提供一个Sitemesh插件,允许在Sitemesh模板中使用Struts标记。 要使用Sitemesh需要包含Freemark,Sitemesh和Sitemesh插件库文件。 配置过滤器 如果需要使用Freemark模板文件作为装饰器文件,需要在web....
sitemesh-2.4.2-src.jar 是sitemesh的源文件jar包,当调试时需要选择该jar包进行资源查找,很好用的页面架构工具
sitemesh官方demo cafe.war
struts2-sitemesh-plugin-2.2.1.1.jarstruts2
SiteMesh 是一个网页布局和修饰的框架,利用它可以将网页的内容和页面结构分离,以达到页面结构共享的目的。Sitemesh是由一个基于Web页面布局、装饰以及与现存Web应用整合的框架。它能帮助我们在由大 量页面构成的...
sitemesh-2.3.zip
sitemesh-2.4.zip