SiteMesh框架的用法。。。。。
来源:互联网 发布:苹果手机下安卓软件 编辑:程序博客网 时间:2024/05/16 12:21
SiteMesh框架是OpenSymphony团队开发的一个非常优秀的页面装饰器框架,它通过对用户请求进行过滤,并对服务器向客户端响应也进行过滤,然后给原始页面加入一定的装饰(header,footer等),然后把结果返回给客户端。通过SiteMesh的页面装饰,可以提供更好的代码复用,所有的页面装饰效果耦合在目标页面中,无需再使用include指令来包含装饰效果,目标页与装饰页完全分离,如果所有页面使用相同的装饰器,可以是整个Web应用具有统一的风格。
下面是一个简单的例子:
将sitemesh-2.4.jar放 到 [web-app]/WEB-INF/lib目录下;
在[web-app]/WEB-INF/新建一个decorators.xml文件,配置如下:
<?xml version="1.0" encoding="UTF-8"?><decorators defaultdir="/WEB-INF/decorators"> <!-- Any urls that are excluded will never be decorated by Sitemesh --> <excludes> <pattern>/exclude.jsp</pattern> <pattern>/exclude/*</pattern> </excludes> <decorator name="main" page="main.jsp"> <pattern>/*</pattern> </decorator></decorators><!--不要忘了在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><?xml version="1.0" encoding="UTF-8"?><decorators defaultdir="/WEB-INF/decorators"> <!-- Any urls that are excluded will never be decorated by Sitemesh --> <excludes> <pattern>/exclude.jsp</pattern> <pattern>/exclude/*</pattern> </excludes> <decorator name="main" page="main.jsp"> <pattern>/*</pattern> </decorator></decorators>不要忘了在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><?xml version="1.0" encoding="UTF-8"?><decorators defaultdir="/WEB-INF/decorators"> <!-- Any urls that are excluded will never be decorated by Sitemesh --> <excludes> <pattern>/exclude.jsp</pattern> <pattern>/exclude/*</pattern> </excludes> <decorator name="main" page="main.jsp"> <pattern>/*</pattern> </decorator></decorators>不要忘了在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>
下面是jsp页面代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %><%@taglib prefix="s" uri="/struts-tags" %><!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><decorator:title default="欢迎使用文档管理系统"/></title><link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/main.css"/><decorator:head/></head><body><s:if test="#session.loginUser!=null">欢迎[${loginUser.nickname }]登录我们的系统 <s:if test="#session.loginUser.type==1"><a href="<%=request.getContextPath()%>/user_list.action">用户管理</a><a href="<%=request.getContextPath()%>/department_list.action">部门管理</a></s:if><a href="<%=request.getContextPath()%>/document_listReceive.action">公文管理</a><a href="<%=request.getContextPath()%>/message_listReceive.action">私人信件</a><a href="<%=request.getContextPath()%>/user_updateSelfInput.action?id=${loginUser.id}">修改个人信息</a> <a href="<%=request.getContextPath()%>/user_showSelf.action?id=${loginUser.id}">个人信息查询</a> <a href="<%=request.getContextPath()%>/user_addEmailInput.action">绑定邮箱</a> <a href="<%=request.getContextPath()%>/login!logout.action">退出系统</a></s:if><s:else><a href="<%=request.getContextPath()%>/login!loginInput.action">用户登录</a></s:else><hr/><h3 align="center"><decorator:title default="文档管理系统"/></h3><decorator:body/><div align="center" style="width:100%;border-top:1px solid; float:left;margin-top:10px;">CopyRight@2013-2016<br/>欢迎浏览本网站!谢谢使用!</div></body></html><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %><%@taglib prefix="s" uri="/struts-tags" %><!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><decorator:title default="欢迎使用文档管理系统"/></title><link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/main.css"/><decorator:head/></head><body><s:if test="#session.loginUser!=null">欢迎[${loginUser.nickname }]登录我们的系统 <s:if test="#session.loginUser.type==1"><a href="<%=request.getContextPath()%>/user_list.action">用户管理</a><a href="<%=request.getContextPath()%>/department_list.action">部门管理</a></s:if><a href="<%=request.getContextPath()%>/document_listReceive.action">公文管理</a><a href="<%=request.getContextPath()%>/message_listReceive.action">私人信件</a><a href="<%=request.getContextPath()%>/user_updateSelfInput.action?id=${loginUser.id}">修改个人信息</a> <a href="<%=request.getContextPath()%>/user_showSelf.action?id=${loginUser.id}">个人信息查询</a> <a href="<%=request.getContextPath()%>/user_addEmailInput.action">绑定邮箱</a> <a href="<%=request.getContextPath()%>/login!logout.action">退出系统</a></s:if><s:else><a href="<%=request.getContextPath()%>/login!loginInput.action">用户登录</a></s:else><hr/><h3 align="center"><decorator:title default="文档管理系统"/></h3><decorator:body/><div align="center" style="width:100%;border-top:1px solid; float:left;margin-top:10px;">CopyRight@2013-2016<br/>欢迎浏览本网站!谢谢使用!</div></body></html>
- SiteMesh框架的用法。。。。。
- SiteMesh 框架的使用
- SiteMesh框架统一布局用法介绍
- 关于sitemesh框架的学习
- SiteMesh框架
- SiteMesh框架
- 页面修饰框架SiteMesh的简单使用
- SIteMesh的了解,前端渲染装饰框架
- sitemesh网页布局和修饰的框架
- 页面修饰框架SiteMesh的简单使用
- struts2.0 中 sitemesh 的用法
- SiteMesh的介绍用法及原理
- SiteMesh的介绍用法及原理
- sitemesh中的decorators.xml的用法
- sitemesh中的decorators.xml的用法
- 使用Sitemesh框架
- 页面布局框架--sitemesh
- Struts使用Sitemesh框架
- Android API Guides/Drawable Animation 翻译
- 【越狱开发】启动iOS设备上的WebInspector功能进行网页调试
- Hadoop安全云盘开发(第0篇)
- Python基础03 序列
- C++数据结构--直接插入排序
- SiteMesh框架的用法。。。。。
- FatMouse's Speed-HDU-动态规划
- Ubuntu常见问题汇总
- expriment : 在MASM工程中使用Unicode字符串
- JAVA 在包里搜索所有的类
- 原生JavaScript中获取元素索引的函数
- Python基础04 运算
- <s:select>和<s:doubleselect>的一般使用
- 更改git默认编辑器:change git default editor to "gedit" or "Sublime Text 2"