Struct2的项目整合SiteMesh实例

来源:互联网 发布:linux互斥锁 编辑:程序博客网 时间:2024/05/09 14:58

1.首先我下载了SiteMesh的jar文件

下载地址:http://download.csdn.net/detail/yakson/5494055

2.我们已经得到了一个SiteMesh2.4.jar文件,将其放到WEB-INF/lib目录下,就算是完成了项目的安装

3.在web.xml中配置SiteMesh的Filter

    <!--定义SiteMesh框架的核心Filter-->    <filter>        <filter-name>sitemesh</filter-name>        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>    </filter>    <!--映射SiteMesh框架的核心Filter过滤所有用户请求-->    <filter-mapping>        <filter-name>sitemesh</filter-name>        <!--使用模式匹配的方式让该Filter处理所有用户请求-->        <url-pattern>*.do</url-pattern>    </filter-mapping>

4.定义装饰器页面

装饰器页面就是普通jsp页面layout_blue.jsp,但是这个页面包含了一些SiteMesh标签。

<%--     Document   : layout_blue    Created on : 2013-6-1, 11:09:45    Author     : qsyang--%><%@page contentType="text/html" pageEncoding="UTF-8"%><%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%><%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%><!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title><decorator:title default="第一个装饰器页面" /></title>        <decorator:head />    </head>    <body>        <decorator:body />    </body></html>

5.那么为了在JSP页面中使用SiteMesh框架的标签库,则需要导入SiteMesh标签库

<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%><%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
不过这些标签库指挥在装饰器页面使用

6.装饰器页面可以放在任意位置,只要在配置文件中配置路径。

因此需要配置decorators.xml文件,放在WEB-INF目录下

<?xml version="1.0" encoding="UTF-8"?><!-- defaultdir 指定装饰器文件所在路径 --><decorators defaultdir="/decorator">    <!--指定layout_blue装饰器,改装饰器使用layout_out.jsp-->    <decorator name="blue" page="layout_blue.jsp">        <pattern>*</pattern>    </decorator></decorators>
7.新建测试页面,index.jsp
通过访问http://localhost:8080/index.jsp 返回的结果就是被装饰器页面装饰过了!

原创粉丝点击