首页 > 其他 > 详细

第三篇sitemesh2整合

时间:2014-03-13 13:01:08      阅读:503      评论:0      收藏:0      [点我收藏+]
一、简述
上一篇中,使用的是sitemesh3和Struts2的整合,在看sitemesh3的资料时,发现这个说明:http://docs.sitemesh.org/
bubuko.com,布布扣
大概意思是,sitemesh3还在测试阶段,如果需要稳定版本的,用sitemesh2代替,笔者要用于开发,为了稳定起见,选择使用了sitemesh2。

二、下载包
1.sitemesh-2.4.rar  sitemesh2包

三、sitemesh2简析
笔者认为,sitemesh2主要从三个方面来学习使用,
  1. sitemesh2的安装和配置。
  2. sitemesh2装饰页面的编写。
  3. sitemesh2标签的掌握和使用。
下面,笔者从以上三个方面来介绍sitemesh2的使用。

四、sitemesh2的安装和配置
1.sitemesh2的安装:
  • 解压sitemesh-2.4.rar ,将sitemesh-2.4.jar放入项目的WebRoot/WEB-INF/lib文件夹下(如果在第二篇基础上,将sitemesh-3.0-alpha-2.jar替换)。
  •  结构图:
    bubuko.com,布布扣
  • sitemesh2安装完成。
2.sitemesh2的配置:
  • 在web.xml中新增以下代码:
<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>
(如果是在第二篇基础上,将名字为sitemesh的filter进行替换。)
  • 在WebRoot/WEB-INF/下新增sitemesh.xml,(如果在第二篇基础上,将sitemesh3.xml进行替换),代码如下:
    <sitemesh>
    <property name="decorators-file" value="/WEB-INF/decorators.xml" />
    <excludes file="${decorators-file}" />
 
    <page-parsers>
        <parser content-type="text/html"
            class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
        <parser content-type="text/html;charset=UTF-8"
            class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
    </page-parsers>
 
    <decorator-mappers>
        <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
            <param name="config" value="${decorators-file}" />
        </mapper>
    </decorator-mappers>
</sitemesh>
  • 在WebRoot/WEB-INF/下新增decorators.xml,代码如下:
<decorators defaultdir="/PAGE-INF/decorator">
    <decorator name="basic" page="basic.jsp">
          <pattern>/*</pattern>
    </decorator>
</decorators>
  • 在WebRoot/PAGE-INF/decorator/下新增basic.jsp,代码如下:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>sitemesh2 Demo</title>
<decorator:head />
</head>
<body bgcolor="#11EE69 " >
<script type="text/javascript">window.status = "Loading: <decorator:title default="INTRANET" />...";</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20" nowrap> </td>
</tr>
<tr>
<td width="1%" nowrap> </td>
<td width="16%" valign="top" nowrap>
<script type="text/javascript">window.status = "Loading: Navigation...";</script>
</td>
<td width="2%" nowrap> </td>
<td valign="top">
<br>
<script type="text/javascript">window.status = "Loading: Document body...";</script>
<div class="docBody"><decorator:body /></div>
</td>
<td width="1%" nowrap> </td>
</tr>
</table>
<br>
<script type="text/javascript">window.status = "Done";</script>
</body>
</html>

  • 结构图:
        bubuko.com,布布扣

  • 运行Tomcat服务器,效果如下:
        bubuko.com,布布扣
  • sitemesh2配置完毕。




第三篇sitemesh2整合,布布扣,bubuko.com

第三篇sitemesh2整合

原文:http://www.cnblogs.com/zyjITravel/p/3597542.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!