Struts2整合SiteMesh的问题.

不管我怎么弄 就是404错误

装饰页 WebRoot/decorators/frame.jsp

 

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="sitemesh-decorator" prefix="decorator" %>
<html>
     <head>
     <title> <decorator:title/> </title>
     <decorator:head/>
    </head>      
<body>
      Hello World  <hr/>
      <decorator:body/>
</body> 
</html>

 

 

main.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>主页标题</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
    主要内容
  </body>
</html>

  decorators.xml

 

<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/decorators">
     <decorator name="main" page="frame.jsp">
         <pattern>/*</pattern>
     </decorator>
</decorators>

 sitemesh-decorator.tld 和 sitemesh-page.tld 都在WEB-INF 下

 

web.xml

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <filter>
        <filter-name>cleanup</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>cleanup</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <jsp-config>
        <taglib>
            <taglib-uri>sitemesh-page</taglib-uri>
            <taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
        </taglib>

        <taglib>
            <taglib-uri>sitemesh-decorator</taglib-uri>
            <taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
        </taglib>
    </jsp-config>

</web-app>

 

不好意思写错了,rewriteFilter不用加:
[code="java"]
<!-- Struts2Cleanup filter -->

struts2CleanupFilter

org.apache.struts2.dispatcher.ActionContextCleanUp

<!-- Sitemesh filter -->
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>
        com.opensymphony.module.sitemesh.filter.PageFilter
    </filter-class>
</filter>

<!-- Struts2 filter -->
<filter>
    <filter-name>struts2Filter</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>

[/code]

web.xml加上rewriteFilter,而且顺序不能错了
[code="java"]
<!-- Url rewrite filter -->

rewriteFilter

org.tuckey.web.filters.urlrewrite.UrlRewriteFilter

<!-- Struts2Cleanup filter -->
<filter>
    <filter-name>struts2CleanupFilter</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ActionContextCleanUp
    </filter-class>
</filter>

<!-- Sitemesh filter -->
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>
        com.opensymphony.module.sitemesh.filter.PageFilter
    </filter-class>
</filter>

<!-- Struts2 filter -->
<filter>
    <filter-name>struts2Filter</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>

[/code]
sitemesh-page.tld和sitemesh-decorator.tld在web.xml里不用加,因为你配置了web-app_2_4.xsd。decorators.xml的encoding="UTF-8"。