sitemesh学习笔记

SiteMesh是一个用来在JSP中实现页面布局和装饰的组件框架,使用起来也很简单,说一下配置步骤:

(1)下载sitemesh的组件包,解压,用到的主要有三个文件:解压后目录里的sitemeshJar包和META-INF目录下的sitemesh-decorator.tldsitemesh-page.tld,将两个tld文件放在项目WEB-INF目录下,将Jar包加入到工程中,在工程WebContent目录下创建一个decorators目录(名字随便起),在该目录下新建一个jsp文件,将网页中固定不变的部分都写在这个jsp文件中,比如标题,索引,还有网站的底部。

(2)WEB-INF下创建decorators.xml<pattern>指定映射url<excludes>中指定的url是不会自动嵌入到模版中的,配置如下

<decorators defaultdir="/decorators">

   <excludes/>

   <decorator name="frame" page="frame.jsp">

      <pattern>/*</pattern>

   </decorator>

</decorators>


Name随便起,路径是这样规定的,defaultdir是模版文件目录,frame.jsp就是刚刚在decorators目录下创建的模版jsp

(3)web.xml中配置sitemesh,包括两部分,一个filter,一个jspconfig如下:

<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>

<jsp-config>
   <taglib>
      <taglib-uri>sitemesh-decorator</taglib-uri>
      <taglib-location>
         /WEB-INF/sitemesh-decorator.tld
      </taglib-location>
   </taglib>
   <taglib>
   <taglib-uri>sitemesh-page</taglib-uri>
   <taglib-location>
      /WEB-INF/sitemesh-page.tld</taglib-location>
   </taglib>
</jsp-config>


4)在decorator目录下的frame.jsp中添加

<decorator:title/>

<decorator:body/>

这种标记,它代表的是你将struts2返回的jsp网页中bodytitle属性自动插入到frame.jsp中。

转载于:https://my.oschina.net/u/274427/blog/69083

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值