在struts2中加入装饰器sitemesh
来源:互联网 发布:软件破解器 编辑:程序博客网 时间:2024/05/22 14:21
装饰器可以统一设置页面的版式,统一引入需要使用的JS,CSS等等作用。
1. 导入sitemesh-xxx.jar包
2. 在web.xml中进行配置
<!-- 定义ActionContextCleanUp过滤器 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ActionContextCleanUp
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
注意ActionContextCleanUp过滤器必须在FilterDispatcher之前配置,
ActionContextCleanUp的主要功能是通知FilterDispatcher执行完毕不要清除
ActionContext,以便sitemesh装饰器可以访问Struts值堆栈。
-->
<!-- 定义SiteMesh的核心过滤器 -->
<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>
</filter-mapping>
<!-- 使用STRUTS2 -->
<filter>
<filter-name>struts</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意三个过滤器的前后顺序,不能换!~
3. 在WEB-INF目录下配置decorators.xml。如下demo
<decorators defaultdir="/decorators">
<excludes>
<pattern>*.html</pattern>
<pattern>/pages/login.do</pattern>
</excludes>
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
<decorator name="header" page="header.jsp" />
<decorator name="fooder" page="footer.jsp" />
</decorators>
4. 在decorators目录下,编写JSP页面
<%-- footer.jsp --%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<div>
退出 帮助<br/>
<s:property value="footerTime"/><br/>
版权所有© 2009
</div>
<%-- main.jsp --%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
<!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>
<title><decorator:title default="同学" />_湖南</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="<%= request.getContextPath() %>/css/style.css" rel="stylesheet" type="text/css" />
<decorator:head />
</head>
<body <decorator:getProperty property="body.class" writeEntireProperty="true" />>
<page:applyDecorator name="header" />
<div class="a b">
<decorator:body />
</div>
<page:applyDecorator name="fooder" />
</body>
</html>
- 在struts2中加入装饰器sitemesh
- 在Struts2中使用SiteMesh插件
- 在Struts2中使用SiteMesh插件
- [转]在Struts2中使用SiteMesh插件
- 在Struts2中使用SiteMesh插件
- struts2之整合sitemesh(定义装饰器页面)
- struts2之整合sitemesh(更复杂的装饰器页面)
- SiteMesh装饰器
- sitemesh装饰器入门
- sitemesh装饰器
- sitemesh装饰器
- 【sitemesh】Jsp的装饰器组件sitemesh
- struts2+SiteMesh(全局统一装饰布局)
- 在Spring中加入Struts2
- Springboot集成sitemesh装饰器
- SiteMesh在JSP中的页面装饰
- Sitemesh整合struts2使用多个装饰器(非/*)的BUG修正
- siteMesh装饰器 指定装饰和不装饰
- 用 Bleachbit 来给 Ubuntu 9.04 “减肥”
- DataReader用完后一定要关闭!
- 程序员的十层楼:大家都来测测你的技术层级
- c++中不同类之间的赋值(重载运算符= 即operator =)
- VC6.0 控件Radio Button的使用
- 在struts2中加入装饰器sitemesh
- 从公司的控件布局的实现类中学到的一点东西
- QQ聊天时如何查询对方的IP地址
- 怀念 WOW
- 女人最常问的几个问题的标准答案
- Oracle和DB2的转换 [转]
- ASP.NET网站发布问题
- 好用的AddWithValue
- 村上春树:“高墙与鸡蛋” 林少华译