1. 加入lib/sitemesh-2.4.2.jar
2.在web.xml 文件中加过滤器
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
3.从sitemesh-2.4.2.jar 中拷出sitemesh-default.xml 复制到工程的WEB-INF目录下,sitemesh.xml
<sitemesh>
<property name="decorators-file" value="/WEB-INF/decorators.xml
"/>
<excludes file="${decorators-file}"/>
<page-parsers>
<parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser
"/>
</page-parsers>
<decorator-mappers>
<mapper class="com.opensymphony.module.sitemesh.mapper.PageDecoratorMapper">
<param name="property.1" value="meta.decorator"/>
<param name="property.2" value="decorator"/>
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.FrameSetDecoratorMapper">
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.AgentDecoratorMapper">
<param name="match.MSIE" value="ie"/>
<param name="match.Mozilla [" value="ns"/>
<param name="match.Opera" value="opera"/>
<param name="match.Lynx" value="lynx"/>
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper">
<param name="decorator" value="printable"/>
<param name="parameter.name" value="printable"/>
<param name="parameter.value" value="true"/>
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.RobotDecoratorMapper">
<param name="decorator" value="robot"/>
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.ParameterDecoratorMapper">
<param name="decorator.parameter" value="decorator"/>
<param name="parameter.name" value="confirm"/>
<param name="parameter.value" value="true"/>
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.FileDecoratorMapper">
</mapper>
<mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
<param name="config" value="${decorators-file}"/>
</mapper>
</decorator-mappers>
</sitemesh>
注意:sitemesh主要用于装饰处理信息,对页面的解析和装饰器配置等等,一般采用默认的即可
配置文件中page-parser 请采用sitemesh.parser.HTMLPageParser 可以解决页面中文乱码问题
4.添加装饰模板decorators.xml配置 文件到WEB-INF 该文件主要用于sitemesh的配置规则。
主要有两个节点:exclude:指定了节点请求不适用任何模板
decorator:指定了模板的位置和文件名,通过pattern指定那些url使用那些模板
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/jsp/decorators"> //指定了模板文件存放的目录
<excludes>
<pattern>/scripts/*</pattern> //排除的连接
</excludes>
<decorator name="store" page="store_main.jsp"> //指定使用的模板
<pattern>/omsStore/*</pattern> //使用装饰的连接
<pattern>/omsCustomer/*</pattern>
</decorator>
5.模板页面的定义
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/security/tags"
prefix="security"%>
<%@taglib uri="http://www.opensymphony.com/sitemesh/decorator"
prefix="decorator"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><decorator:title default="********" />
</title>
<link href="<c:url value="/styles/jquery-ui/jquery-ui.css" />"rel="stylesheet" type="text/css" />
<link href="<c:url value="/styles/tools.css" />"rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/styles/list.css"></link>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/styles/jquery.lightTreeview.css"></link>
<script type="text/javascript"
src="${pageContext.request.contextPath}/scripts/jquery.lightTreeview.pack.js">
</script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/scripts/jquery.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/scripts/pglist.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/scripts/selectOperate.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/scripts/jquery.tools.min.js"></script>
<decorator:head />
</head>
<body>
<div class="tableBox">
<decorator:body />
</div>
</body>
</html>
6.总结:1.模板页得作用主要是将功能页中通用的、与业务功能不相关的代码进行分离,统一管理,从而达到代码的重用,如页面布局,css,js等等。
2.凡是能经过过滤器请求的页面,都可以使用上面的js,css等,页面自身的内容放到<decorator:body />
中
3.<decorator:head />
读取装饰器页面head的内容
4.<decorator:title/>
读取装饰器页面title的内容
7.常见的问题:
1.在运行过程中无法显示模板页,查看配置的路径(pattern),查看web.xml文件Filter是否采用sitemesh.filter.pageFilter
2.无法显示功能页,只能显示模板页,查看<decorator:body />
的位置
3.在web logic 中出现了中文乱码,查看sitemesh.xml文件 <page-parsers> 是否采用sitemesh.parser.HTMLPageParser
8.标签:
被用于建立装饰器页面.
<decorator:head />
<decorator:body />
<decorator:title />
<decorator:getProperty />
<decorator:usePage />
被用于从原始内容页面访问装饰器.
<page:applyDecorator
/>
<page:param
/>
9.性能问题:
使用sitemesh和不使用sitemesh对于虚拟机堆内存的使用差异不太大,但
是在GC次数上的差异很大。从GC日志的详细信息可以看出,在使用sitemesh时,发生次要GC(Minor
GC)的频率非常的高,可以推断在运行时期产生了大量的短生命周期的对象,然后又迅速的被释放,GC在新生代就已经完成了。主要GC(Major GC,
Full
GC)在使用sitemesh和不使用的情况下,均发生了1次,而且这1次主要GC也是在resin启动中发生的,不是应用在进行压力测试时发生的。由于
使用sitemesh时的GC次数远远大于不使用sitemesh,所以在整个测试过程中,GC上消耗的时间也是差异非常大的。
不使用sitemesh时完成的请求数是使用sitemesh时的144.3%。同时页面响应时间也仅为使用sitemesh时的69.0%。
从上述测试数据来分析,使用sitemesh对于系统性能是有较大的影响的,主要表现在GC的次数会显著增多。建议在大压力、页面内容大的系统中,慎重选择sitemesh,并且使用之前对其带来的性能影响进行一个较为合理、全面的评估。
分享到:
相关推荐
这个是sitemesh在项目中的应用,还有相关的jar包和资料,最重要的还有例子。
刚上手ssm及maven时一直会问基础配置,以下可做参考,sitemesh标签的使用
SiteMesh框架在Java项目中的应用
它能帮助我们在由大 量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的banner,一致的版权,等等。 它不仅仅能处理动态的内容,如jsp,php,asp等产生的内容,它也能处理静态的内容,如htm的内容...
sitemesh 将网页逆向包含,不用每个页面include公共页面,而是配置后将所有页面被公共页面自动组合起来
简单的sitemesh maven项目。亲测可用
sitemesh教程
它能帮助我们在由大量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的banner,一致的版权,等等。 它不仅仅能处理动态的内容,如jsp,php,asp等产生的内容,它也能处理静态的内容,如htm的内容...
测试用报表架构(sitemesh+struts2+birt)
Sitemesh是由一个基于Web页面布局、装饰及与现存Web应用整合的框架。它能帮助我们再由大量页面工程的项目中创建一致的页面布局和外观,如一致的导航条、一致的banner、一致的版权等。
量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的banner,一致的版权,等等。 它不仅仅能处理动态的内容,如jsp,php,asp等产生的内容,它也能处理静态的内容,如htm的内容, 使得它的内容也...
这个东东 是我们项目里面改版的 之前在项目里面 是Windows下面的 tomcat里面 开发的 但是 后来移植到weblogic下面后 就出现乱码 还有 就是 页面无法正常显示。于是就改了 这个 sitemesh 包。
NULL 博文链接:https://zdz8207.iteye.com/blog/479682
使用spring+springmvc框架 整合了Mybatis持久层框架 整合Druid用于数据库连接,并使用Druid对业务层...使用了sitemesh对网页进行布局和修饰 使用了loginFilter对访问进行登录过滤 使用了CheckCodeServlet生成验证码图片
,在本次项目中使用了不少新技术新方法,ibator,aop缓存,sitemesh由于使用了这些新技术使得开发效率有了不小的提升。 现在我向大家介绍一个小工具, ibator-huoniao通过它你可以通过配置少量参数,通过一键生成...
集成了struts2,spring2,hibernate3,以及velocity和sittemesh的项目源代码,有兴趣的可以下载下,关键是集成velocity有点难度,呵呵.
1.4 Web项目中使用Struts2初探 20 第2章 Web基础技术简介 31 2.1 B/S和C/S系统区别 31 2.2 JSP和Servlet介绍 32 2.3 XML知识介绍 34 第3章 Struts2核心技术 37 3.1 使用web.xml配置Struts2实现Web项目Struts2应用 37...
S2SH框架集成项目 通过S2SH和Sitemesh框架集成的ORM和库存管理系统
尽管Spring框架自身对编程模型没有限制,但其在Java应用中的频繁使用让它备受青睐,以至于后来让它作为EJB(EnterpriseJavaBeans)模型的补充,甚至是替补。Spring框架为开发提供了一系列的解决方案,比如利用控制...
开发框架集成Struts2+Spring+hibernate+sitemesh+junit 项目中还有一个登陆功能 由于Jar比较多 上传时去掉一些,请自己加上