`

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,其他自定义

...

 

 

 

 

分享到:
评论

相关推荐

    SiteMesh入门学习

    SiteMesh 是一个开源的网页布局框架,用于Java Web应用程序,其主要目的是解决页面布局和装饰的问题。通过使用Decorator模式,SiteMesh能够将通用的头部、底部、侧边栏等元素统一管理,使得开发者无需在每个单独的...

    sitemesh入门demo

    这个demo是基于博主的**Sitemesh入门和使用笔记**,提供了对应的源码供学习者实践和参考。以下是关于Sitemesh的详细讲解: 1. **安装与配置** - 首先,你需要将Sitemesh的JAR文件添加到你的项目类路径中。这可以...

    SITE MESH学习笔记

    SiteMesh 通过GOF(GoF,设计模式之父)的Decorator模式实现这一目标,允许开发者定义全局的页面头部、底部、侧边栏等元素,然后自动应用到所有或特定的Web页面上。 SiteMesh 的工作原理是通过过滤器(Filter)机制...

    SSH核心笔记

    SSH框架即Struts + Spring + Hibernate,是Java Web开发领域中一个非常流行的轻量级应用框架组合。本篇内容将围绕Struts、Spring、Hibernate这三个核心组件展开讨论,并简要介绍与之相关的SiteMesh等技术。 ### 一...

    grails开发笔记

    Grails 是一款用于 Web 应用开发的开源框架,它基于 Groovy 编程语言,并集成了 Spring、Hibernate 和 SiteMesh 等成熟技术栈。其核心特性之一是“规约取代配置”(Convention Over Configuration, CoC),这一理念...

    xdoclet_appfuse打包

    适合初学者和有经验的开发者去深入理解和使用AppFuse和XDoclet,同时也涵盖了SpringSide、SiteMesh、Acegi Security(Spring Security)和Log4j等其他相关技术,对于构建和管理Java Web应用来说是一份宝贵的资源库。

    Struts2.1讲义

    #### 第3章:Struts 2的核心技术 - **3.1 使用web.xml配置Struts 2实现Web项目** - **配置前端过滤器**:通过在`web.xml`中配置Struts 2的前端过滤器`FilterDispatcher`,确保所有请求都经过Struts 2处理。 - **...

    Freemarker 语法规则

    通过阅读`freemarker语法.docx`和`freemarker笔记1.txt`,你可以更深入地了解这些规则,并结合实际项目进一步掌握Freemarker的使用。同时,参考提供的博客链接(https://kingpingping.iteye.com/blog/1144477),...

Global site tag (gtag.js) - Google Analytics