说明:我这里使用struts的版本是2.18版本的,对应的sitemesh是2.42的
必须要的架包有:(除了struts架包以外)
sitemesh-2.42.jar
struts2-sitemesh-plugin-2.2.1.jar
首先我们来配置web.xml
--------------------------------------web.xml中添加如下内容----------------------------------------
<!-- 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>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
------------------------------web.xml结束-------------------------------------------------------------
注意:先配置sitemesh拦截器,在配置struts的拦截器,也就是sitemesh拦截器在struts之前
第二步:
在webroot目录下面建decorators文件夹,里面放装饰的模型jsp(注意:名称必须为:decorators)
我这里名叫mode.jsp,这个名称是可以随便修改的
---------------------------mode.jsp内容--------------------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!--引入sitemesh的标签-->
<%@taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%>
<!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">
<script type="text/javascript" src="jQuery.js"></script>
<decorator:head>
<!--- 其他的页面中head的内容会在这里添加-->
</decorator:head>
</head>
<body>
<div>中华人民共和国万岁 </div>
<!-- 例如:上面的一句话将会在每个页面中添加--->
<decorator:body>
<!--- 其他的页面中body的内容会在这里添加-->
</decorator:body>
</body>
</html>
-------------------------------------------------------------------
最重要的decorators.xml配置 ,其位置和web.xml位置相同
--------------------------------decorators.xml---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<decorators defaultdir="/decorators">
<!--excludes结点则指定了哪些路径的请求不使用任何模板-->
<excludes>
<pattern>/index.jsp*</pattern>
<pattern>/login/*</pattern>
</excludes>
<!--decorator结点指定了模板的位置和文件名,通过pattern来指定哪些路径引用哪个模板-->
<decorator name="main" page="mode.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
分享到:
相关推荐
Struts 2.0提供一个Sitemesh插件,允许在Sitemesh模板中使用Struts标记。 要使用Sitemesh需要包含Freemark,Sitemesh和Sitemesh插件库文件。 配置过滤器 如果需要使用Freemark模板文件作为装饰器文件,需要在web....
struts2+sitemesh例子 该例子描述了struts2+sitemesh的配置,比较实用
struts2-sitemesh-plugin-2.2.1.1.jarstruts2
struts2-sitemesh-plugin-2.1.6.jar
struts2-sitemesh-plugin-2.0.8.jar
NULL 博文链接:https://takeme.iteye.com/blog/1716488
struts2-sitemesh_入门收集struts2-sitemesh_入门收集
这个是sitemesh在项目中的应用,还有相关的jar包和资料,最重要的还有例子。
一个Struts2+Spring2.5+SiteMesh的小DEMO,仅供大家做个参考!我也刚学会。欢迎大家多交流!
Struts2.0 与 sitemesh的例子 博文链接:https://jiangyou001.iteye.com/blog/183698
struts2与sitemesh整合所需的两个最新架包sitemesh-2.4.2,struts2-sitemesh-plugin-2.1.8
struts2-sitemesh-plugin-2.1.8.1.jar
解决 java.lang.NoSuchFieldException: DEFAULT_PARAM>问题,下载后替换即可。
sitemesh 使用例子。 <?xml version="1.0" encoding="utf-8"?> <decorators defaultdir="/decorators"> <!-- 此处用来定义不需要过滤的页面 --> <excludes> </excludes> <!-- 用来定义装饰器要过滤的...
struts框架与sitemesh框架整合的插件,在java web开发中可以制作模板页,使自己做的网站看起来更专业
struts2sitemesh-freemarker 源码
Sitemesh是由一个基于Web页面布局、装饰以及与现存Web应用整合的框架。它能帮助我们在由大 量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的banner,一致的版权,等等。 它不仅仅能处理动态的...
sitemesh 例子,里面举例一个简单例子,而且还有一个简单文档说明