一.需要包(两个),我用的是struts-2.1.8.1,注意版本
struts2-sitemesh-plugin-2.1.8.1.jar
sitemesh-2.4.2.jar
二.创建decorators.xml
<?xml version="1.0" encoding="utf-8"?>
<decorators defaultdir="/decorators">
<!--excludes结点则指定了哪些路径的请求不使用任何模板-->
<!--/index.jsp和凡是以/login/开头的请求路径一律不使用模板-->
<excludes>
<pattern>/index.jsp*</pattern>
<pattern>/login/*</pattern>
</excludes>
<!--decorator结点指定了模板的位置和文件名,通过pattern来指定哪些路径引用哪个模板-->
<decorator name="main" page="mode.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
三.在WebRoot下创建decorators
文件夹,其下创建layout.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="decorator"
uri="http://www.opensymphony.com/sitemesh/decorator"%>
<%@taglib prefix="page" uri="http://www.opensymphony.com/sitemesh/page"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><decorator:title default="嘻嘻哈哈" />
</title>
<decorator:head />
</head>
<body id="page-home">
<div style="background-color: red;width:100%;height: 100px;">
头
</div>
<div>
<!-- 这里的内容由引用模板的子页面来替换 -->
<decorator:body />
</div>
</body>
</html>
四.测试,创建index.jsp,根据配置文件,他不使用模板
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>index.jsp</title>
</head>
<body>
<form action="login.jsp">
<input type="submit" />
</form>
</body>
</html>
创建login.jsp,根据配置文件,他使用模板
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>行么</title>
</head>
<body>
<form action="login.jsp">
<input type="text" />
<input type="submit" />
</form>
</body>
</html>
测试可以看到效果
我的开发环境
Myeclipse5.5
参考于:http://blog.sina.com.cn/s/blog_4d429a290100d62c.html
谢谢!
分享到:
相关推荐
struts2-sitemesh-plugin-2.2.1.1.jarstruts2
Struts 2.0提供一个Sitemesh插件,允许在Sitemesh模板中使用Struts标记。 要使用Sitemesh需要包含Freemark,Sitemesh和Sitemesh插件库文件。 配置过滤器 如果需要使用Freemark模板文件作为装饰器文件,需要在web....
struts2-sitemesh-plugin-2.0.8.jar
struts2-sitemesh-plugin-2.1.6.jar
struts2+sitemesh例子 该例子描述了struts2+sitemesh的配置,比较实用
struts2-sitemesh_入门收集struts2-sitemesh_入门收集
NULL 博文链接:https://takeme.iteye.com/blog/1716488
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>问题,下载后替换即可。
struts框架与sitemesh框架整合的插件,在java web开发中可以制作模板页,使自己做的网站看起来更专业
一个Struts2+Spring2.5+SiteMesh的小DEMO,仅供大家做个参考!我也刚学会。欢迎大家多交流!
Sitemesh是由一个基于Web页面布局、装饰以及与现存Web应用整合的框架。它能帮助我们在由大 量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的banner,一致的版权,等等。... struts2 就不用说了撒
Struts2.0 与 sitemesh的例子 博文链接:https://jiangyou001.iteye.com/blog/183698
struts2sitemesh-freemarker 源码
struts2-config-browser-plugin-2.3.24.jar, ...struts2-sitemesh-plugin-2.3.24.jar, struts2-spring-plugin-2.3.24.jar, struts2-struts1-plugin-2.3.24.jar, struts2-tiles-plugin-2.3.24.jar,
包含struts2-core-2.5.10.1.jar,struts2-jfreechart-...struts2-sitemesh-plugin-2.5.10.1.jar,struts2-spring-plugin-2.5.10.1.jar,struts2-testng-plugin-2.5.10.1.jarstruts2-tiles-plugin-2.5.10.1.jar等jar包
SiteMesh 开发jar包 Struts2 SiteMesh 插件 jar包