sitemesh配置及示例myeclipse下

1 环境:myeclipse,tomcat,jdk1.6

2. (1)新建web工程sitemeshDemo:

(2)下载sitemesh.jar, sitemesh-decorator.tld,sitemesh-page.tld 地址http://www.opensymphony.com

将sitemesh.jar复制到WEB-INF/lib,sitemesh-decorator.tld和sitemesh-page.tld 复制到WEB-INF下;

(3)修改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>
</filter-mapping>

3.在WebRoot下建立文件夹myDecorators;在WEB-INF下建立 decorators.xml内容如下

<?xml version="1.0" encoding="UTF-8"?>

<decorators defaultdir="/myDecorators">
<decorator name="main" page="main.jsp">
<pattern>*</pattern>
</decorator>
</decorators>

4 在WebRoot/myDecorators下新建两个页面main.jsp,index.jsp

其中main.jsp内容如下

<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/sitemesh-decorator.tld" prefix="decorator" %>
<html>
<head>
<title><decorator:title default="装饰器页面..." /></title>
<decorator:head />
</head>
<body>
sitemesh的例子<hr>
<decorator:body />
<hr>copyright xxx公司
</body>
</html>

被装饰的页面index.jsp内容如下

<%@ page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>Agent Test</title>
</head>
<body>
<p>你可以在这里加入你的内容.</p>
</body>
</html>

5.发布运行项目,在浏览器地址栏输入http://10.0.12.207:8080/SsitemeshDemo/myDecorators/index.jsp, 成功了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值