zoukankan      html  css  js  c++  java
  • 在SSH框架中增加SiteMesh的支持

    1)引入jar包,如下两个jar包需要导入到系统的lib文件夹中:

    sitemesh-2.4.jar
    struts2-sitemesh-plugin-2.2.1.1.jar

    2)修改web.xml增加相应的过滤器
     
    <!-- use ContextLoaderListener initialize Spring container -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
     
    <!-- difine ActionContextCleanUp filter -->
    <filter>
    <filter-name>struts-cleanup</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
    </filter>
     
    <!-- define SiteMesh core filter-->
    <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
    </filter>
     
    <!-- Struts 2 core Filter -->
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
     
    <!-- first: cleanup filter  -->
    <filter-mapping>
    <filter-name>struts-cleanup</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
     
    <!-- second: sitmesh core filter  -->
    <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
     
    <!-- third: struts2 core filter -->
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    3)在web.xml同级增加一个sitmesh的配置文件decorators.xml,文件内容如下:

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

    4)在decorators文件夹中增加模板文件main.jsp 以及menu.jsp:
    main.jsp文件如下:

    <%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>

    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
    <%@taglib prefix="s" uri="/struts-tags"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title><decorator:title default="AdminPortal title"/></title>
    <s:head/>
    </head>
    <body>
    <table width="95%" border="1" align="center">
    <tr>
    <td colspan="2">
    <page:applyDecorator page="/jsp/top.html" name="menu"/>
    </td>
    </tr>
    <tr>
    <td width="15%">
    <page:applyDecorator page="/jsp/menu.html" name="menu"/>
    </td>
    <td>
    <decorator:body/>
    </td>
    </tr>
    </table>
    </body>
    </html>

    menu.jsp文件如下:

    <%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>

    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
    <%@taglib prefix="s" uri="/struts-tags"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title><decorator:title default="AdminPortal title"/></title>
    <s:head/>
    </head>
    <body>
    <table width="50%">
    <tr>
    <td><decorator:body/></td>
    </tr>
    </table>
    </body>
    </html>

    再次运行的时候,就可以看到如下的内容:

    作者 陈字文(热衷于PMORACLEJAVA等,欢迎同行交流)EMAIL:ziwen@163.com  QQ:409020100



  • 相关阅读:
    JavaWeb03-4.0.0版本的pom.xml
    Git学习(上)
    JavaWeb02-如何创建一个基础的Maven项目
    JavaWeb01-maven环境搭建
    HTML5学习
    RSA和AES加密解密过程
    mysql安装失败,最后一步无响应
    powerDesign16通过PLSql中导出的建表语句,建立E-R图
    PLSQL developer+instantclient_11_2实现远程连接Oracle数据库
    分享黄维仁博士关于亲密关系的佳言
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3331456.html
Copyright © 2011-2022 走看看