在ssh项目中中引入sitemesh框架,实现装饰页和内容的分离,个人理解为sitemesh过滤了请求的连接,对于需要装饰的页面加载完装饰页面的部分,实际上有点儿像include这个属性,不同的是include直接把jsp整体加进去,而sitemesh的decorator是分title、head、和body的内容分别嵌套进入装饰页。
不过需要注意的是到浏览器端js和css等加载的顺序,被装饰的页面的js、css以及JavaScript是排在装饰页面内包含的js、css等的前面的,所以如果装饰页面和被装饰页面都有对一个组件的定义,那么这个组件最后显示的效果是被装饰页面里面定义的效果。
现实的例子是我在被装饰页面里面写了表格的初始化,而在装饰页面里面没有写,结果是刷新一下,效果闪一下又不见了。而如果在装饰页面里面定写了初始化,被装饰页面就可以省略了。
1、在项目中引入sitemesh
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>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> </filter-mapping> <filter-mapping>
3、添加sitemesh配置文件:decorators.xml
<?xml version="1.0" encoding="UTF-8"?> <decorators defaultdir="/decorators"> <excludes> <pattern>/login.*</pattern> <pattern>/error.*</pattern> </excludes> <decorator name="main" page="MainBody.jsp"> <pattern>/WEB-INF/ServiceManage/*</pattern> </decorator> </decorators>
exclude代表排除不要装饰的页面,而decorator表示装饰的属性,page里面的jsp表示你的装饰页
pattern表示你要被装饰页面的路径,把你要装饰的页面放在这个目录下面,当然也可以定义多个
4、装饰页面MainBody.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!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" xml:lang="en" lang="en"> <head> <base href="<%=basePath%>"/> <decorator:head></decorator:head> <title>XX系统—— <decorator:title default="欢迎你!"></decorator:title></title> <meta http-equiv="pragma" content="no-cache"/> <meta http-equiv="cache-control" content="no-cache"/> <meta http-equiv="expires" content="0"/> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/> <meta http-equiv="description" content="This is my page"/> <link rel="stylesheet" type="text/css" href="styles.css"/> <script language=javascript src="clock.js"></script> <%java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); java.util.Date currentTime = new java.util.Date(); String time = simpleDateFormat.format(currentTime).toString(); %> </head> <body onload="showtime()"> <div id="container"> <div id="header"> XX系统 </div> <div id="main"> <div id="menu" > <%@include file="/menus.jsp" %> </div> <div id="content"> <decorator:body></decorator:body> <br/><a href=Login.jsp>注销</a> </div> </div> <div id="footer" > 版权所有 <form name=clock > <input name="thetime" style="font-size: 9pt;color:#000000;border:0" size="30"/> </form> <%=time%> </div> </div> </body> </html>
相关推荐
采用webwork+spring+ibatis+sitemesh组合开发的框架示例系统
struts2+sitemesh例子 该例子描述了struts2+sitemesh的配置,比较实用
jQuery+json+struts2+spring3(事务,AOP,IoC即DI)+hibernte3+EhCache+oscache+proxool+MySQL+SiteMesh+Gzip lj例子
集成了struts2,spring2,hibernate3,以及velocity和sittemesh的项目源代码,有兴趣的可以下载下,关键是集成velocity有点难度,呵呵.
springmvc+mybatis+ehcache+jsp+sitemesh完美运行
springmvc + mybatis + sitemesh3登陆 超简洁例子mysql 增加了MD5验证
springmvc + mybatis + sitemesh3 超简洁例子 整合springmvc mybatis 方法请看: http://blog.csdn.net/kokoyuo/article/details/52808510
Struts2+Spring+Hibernet+JPA+sitemesh+log4j整合。
Maven+SpringMVC+Hibernate4+Security+CXF+SiteMesh,用户权限完全自定义
一个Struts2+Spring2.5+SiteMesh的小DEMO,仅供大家做个参考!我也刚学会。欢迎大家多交流!
springmvc+mybatis+ehcache+freemarker+sitemesh页面布局(注解)整合实例完美运行
Struts2+Spring+Hibernate+sitemesh做的一个在线音乐站点写的一个在线音乐 的站点.功能实现的相对比较粗糙(如歌曲列表没考虑分页什么的),另外只能使用IE(使用了ActiveX 控件播放音乐的).
springmvc + mybatis + sitemesh3 简洁例子 springmvc + mybatis 整合过程: http://blog.csdn.net/kokoyuo/article/details/52808510
MiddleGen-Hibernate: 本书使用版本:2.1 ... modtime=1096973436&big_mirror=0 下载文件:middlegen-2.1.zip MiddleGenIDE插件: 本书使用版本:1.2.0 ...(7)Sitemesh: ...下载文件:sitemesh-2.3.zip
Sitemesh是由一个基于Web页面布局、装饰以及与现存Web应用整合的框架。它能帮助我们在由大 量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的banner,一致的版权,等等。 它不仅仅能处理动态的...
基于struts2.1.6 ssh+sitemesh
sitemesh 将网页逆向包含,不用每个页面include公共页面,而是配置后将所有页面被公共页面自动组合起来
NULL 博文链接:https://hufeng.iteye.com/blog/340106
开发框架集成Struts2+Spring+hibernate+sitemesh+junit 项目中还有一个登陆功能 由于Jar比较多 上传时去掉一些,请自己加上
jqueryui界面框架_sitemesh布局框架