`

sitemesh3应用笔记

 
阅读更多

作为一款JSP-WEB视图组织布局模板,sitemesh采用的低侵入式的JSP过滤器方式载入WEB流程的,可以装饰目标jsp页,可以与常用的JSP应用框架整合,以及整合模板组件比如Freemarker,初步设置好之后再后面的应用jsp页面及java代码中都不需要再涉及,这是优点。比较常用的有2.4.2版本,目前有3.0.1版本,两个版本的配置方式有较大区别,从2升到3貌似碰到很多问题,比如乱码问题,但也并没说就非得用3.0不是吗。描述文档见“http://wiki.sitemesh.org/wiki/display/sitemesh/Home”。

相比较而言,同类的jsp布局框架tiles3,采用类似,侵入性较多,在后续java编码跳转视图上都要考虑目标jsp路径与tiles定义配置匹配,但是据说应用tiles3框架的展现加载效率要高点,而且定义比较灵活,运用方式贯穿每个页面流程。

两者比较,表格中Decorator代表sitemesh:

Aspect Composite View Decorator
Reusability The different parts of the page (template and pieces) can be reused across the whole application. Each decorator can be reused, but the decoration itself can be applied to one page at a time.
Ease of configuration Each page must be defined explicitly. The decorator can be applied even to the entire application.
Runtime configuration The pages can be configured and organized at runtime Since one page is decorated at a time, this feature is not present.
Performances Low overhead for composition. The page to be decorated has to be parsed.

 

 

 

sitemesh2的配置方式:

1,添加所需的jar包,以及整合入其他框架的插件类jar包

sitemesh-2.4.2.jar,比如:struts2-sitemesh-plugin-2.3.xx.jar

2,在webapp的web.xml配置过滤器

<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>

 3,配置WEB-INF/decorators.xml(与其他框架整合会被自动加载)

<?xml version="1.0" encoding="UTF-8"?>
<decoratos defaultdir="/jsps">  
    <decorator name="myDecorator" page="decorator.jsp">  
        <pattern>/*</pattern> 
    </decorator>  
    <excludes>   
    	<pattern>*.html</pattern>       
		<pattern>*.js</pattern>  
		<pattern>*.gif</pattern>  
		<pattern>*.jpg</pattern>  
		<pattern>*.png</pattern>  
		<pattern>*.css</pattern>  
	</excludes>
	<decorator name="panel" page="/jsps/footer.jsp"></decorator>	
</decoratos> 

4,建立配置装饰页(框架页,jsp)

jsp页中引入自定义标签“decorator”对应html的body/head/title,“page”标签对应其他子页面jsp页或者html

5,其他自定义...

 

sitemesh3的配置方式:

1,添加jar及相关框架插件jar

sitemesh-3.0.1.jar,比如:struts2-sitemesh-plugin-2.3.xx.jar

2,在webapp的web.xml配置过滤器

 

3,添加sitemesh3.xml至WEB-INF/,比如

<sitemesh>
  <mapping path="/*" decorator="/decorator.html"/>
  <mapping path="/admin/*" decorator="/admin-decorator.html"/>
  <mapping path="/index.jsp*" exclue="true" />

</sitemesh>

 4,建立配置装饰页(比如decorator.html框架页,jsp或者html页)

(与2.0不同),因为装饰页可以是纯html,不引入jsp标签,仅仅是自定义html标签"sitemesh:write",插入页面的head/body/tilte:如"<sitemesh:write property='body'/>"

那么引入其他jsp/html就得靠其他方式了。

5,其他自定义

...

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics