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



  • 相关阅读:
    关于数据库的索引知识
    RESTful API设计相关
    Coroutine(协程)模式与线程
    Python网络编程中的服务器架构(负载均衡、单线程、多线程和同步、异步等)
    读懂diff
    Linux学习笔记——如何使用echo指令向文件写入内容
    ubuntu中执行定时任务crontab
    网络编程之异步IO,rabbitMQ笔记
    走进docker的世界之入门篇
    xml基础
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3331456.html
Copyright © 2011-2022 走看看