随笔 - 16  文章 - 0  trackbacks - 0
<2012年3月>
26272829123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿

随笔档案

友情链接

搜索

  •  

最新评论

阅读排行榜

评论排行榜

调试环境:struts,Spring,jsp

第一步:安装插件
在pom.xml文档中增加相应依赖:

<dependency>
   <groupId>org.sitemesh</groupId>
   <artifactId>sitemesh</artifactId>
   <version>2.4.2</version>
  </dependency>
  <dependency>
   <groupId>org.apache.struts</groupId>
   <artifactId>struts2-sitemesh-plugin</artifactId>
   <version>2.3.1.2</version>
  </dependency>

第二步:配置监听
在web.xml文档中,增加过滤器
<!-- sitemesh 装饰器 -->
 <filter>
      <filter-name>sitemesh</filter-name>
      <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
 </filter>
  <filter-name>sitemesh</filter-name>
      <url-pattern>*</url-pattern>
 </filter-mapping>

第三部:配置装饰器
在WEB-INF文件夹下,新建装饰器配置文档:decorators.xml
文档内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE decorators PUBLIC "-//OpenSymphony//SiteMesh 1.5 Decorators//EN" "http://www.opensymphony.com/sitemesh/dtd/sitemesh_1_5_decorators.dtd">
<decorators defaultdir="/decorators"><!--文件夹可以修改-->
 <!-- 放弃装饰部分 -->
     <excludes>
          <pattern>/40*.jsp</pattern>
          <pattern>/*ajax=true*</pattern>
          <pattern>/scripts/dojo/*</pattern>
          <pattern>/struts/dojo/*</pattern>
          <pattern>/resources/*</pattern>
     </excludes>
 <!--装饰名称,可以设置多个-->
 <decorator name="default" page="default.jsp">
      <pattern>*</pattern>
 </decorator>
</decorators>

第四步  在WEB-INF文件夹下,新建sitemesh配置文档:sitemesh.xml
<sitemesh>
    <property name="decorators-file" value="/WEB-INF/decorators.xml"/>
    <excludes file="${decorators-file}"/>
    <page-parsers>
        <parser default="true" class="com.opensymphony.module.sitemesh.parser.FastPageParser"/>
        <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.FastPageParser"/>
        <parser content-type="text/html;charset=ISO-8859-1" class="com.opensymphony.module.sitemesh.parser.FastPageParser"/>
    </page-parsers>

    <decorator-mappers>
        <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
            <param name="config" value="${decorators-file}"/>
        </mapper>
    </decorator-mappers>
</sitemesh>



第五部:编写装饰模板并引用标签
在<decorators defaultdir="/decorators">指定的文件下,新加模板:default.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
 pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <%@ include file="/common/meta.jsp"%>
    <title><decorator:title /> | Demo</title>
    <decorator:head />
</head>
<body
     <decorator:getProperty property="body.id" writeEntireProperty="true"/>
     <decorator:getProperty property="body.class" writeEntireProperty="true"/>>
     <div id="page">
          <div id="header" class="clearfix">
           <jsp:include page="/common/header.jsp" />
          </div>

          <div id="content" class="clearfix">
           <div id="main">
           <%@ include file="/common/messages.jsp"%>
      <h1>
           <decorator:getProperty property="meta.heading" />
      </h1>
          <decorator:body />
     </div> 
  <c:set var="currentMenu" scope="request">
   <decorator:getProperty property="meta.menu" />
  </c:set>
 
  <div id="nav">
   <div class="wrapper"></div>
    <hr />
   </div>
   <!-- end nav -->
  </div>
 
  <div id="footer" class="clearfix">
   <jsp:include page="/common/footer.jsp" />
  </div>
 </div>
</body>
</html>

第五部:测试
期待正确的结果。

posted on 2012-03-15 09:00 民工二代 阅读(1537) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: