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



  • 相关阅读:
    SQL的四种连接(内连接,外连接)
    MySQL连表操作之一对多
    [转]Mysql连表之多对多
    Hibernate笔记二
    Hibernate框架报错:org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.mikey.hibernate.domain.Person.pid
    Hibernate框架:org.hibernate.exception.SQLGrammarException: Cannot open connection at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java92)
    [转]网络编程三要素
    Hibernate笔记一
    JavaScript高级特征之面向对象笔记
    Myeclipse创建HTML文件中文显示乱码问题
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3331456.html
Copyright © 2011-2022 走看看