`
liangjian103
  • 浏览: 172952 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Sitemesh例子分享

 
阅读更多

sitemesh是表现层的技术,它将公用的部分抽出来了,就不用再页面中加入大量的<include>标签了

1.

   在/WEB-INF/lib中加入sitemesh的jar包,这里使用sitemesh-2.4.1.jar

2.在web.xml中加入sitemesh的过虑器:

   <filter>
           <filter-name>sitemesh</filter-name>
           <filter-class>
                     com.opensymphony.sitemesh.webapp.SiteMeshFilter
          </filter-class>
   </filter>
   <filter-mapping>
            <filter-name>sitemesh</filter-name>
           <url-pattern>/*</url-pattern>
   </filter-mapping>

 

3.在/WEB-INF下添加一个名为decorators.xml的文件,内容为:

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
     <decorator name="main" page="default.jsp">
            <pattern>*</pattern>
     </decorator>
</decorators>

 

4.在webroot下加入decorator文件夹,并加入一个文件default.jsp,内容为:

<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%>
<html>
     <head>
      <title>

         <!--把请求的原始页面的body内的全部内容插入到相应位置-->
         <!-- 如果页面中没有title就用default设置的 -->
         <decorator:title default="test sitemesh" />
       </title>
    <decorator:head />
</head>
<body>
     <center>
        <font color="red" size="7">top</font><!-- 头部 -->
         <hr>
          <decorator:body /> <!-- 把请求的原始页面的body内的全部内容插入到相应位置 -->
         <hr>
          <font color="red" size="7">bottom</font><!-- 尾部 -->
        </center>
</body>
</html>

 

这样就已经完成了一个最简单的实例了,访问项目中的任何一个页面就可以看到效果了 ^_^

 

工程下载

分享到:
评论
1 楼 androidzjb 2012-04-18  
谢谢分享爱 

相关推荐

Global site tag (gtag.js) - Google Analytics