找遍了所有技术论坛都没有关于sitemesh对于struts2转发地址不进行装饰的贴子
而网上的都是拿直接请求.jsp的例子说的倒处都是,直接访问这个jsp是可以用,但若请求是通过struts2的action转发回来的页面却没有用
费话不多说,直接把代码贴给有需要的朋友吧
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<filter>
<filter-name>characterEncoding</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:resources/configuration/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>sitemeshFilter</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemeshFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/index</welcome-file>
</welcome-file-list>
</web-app>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
还有就是需要按照顺序 其实这个我也没测过,但人们都说要按照顺序我也就照着来呗,但这不是最关健,最关健的还是
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
这两句代码,说说原因
默认情况下,filter 的拦截范围是:reuqest,也就是说只会对请求进行拦截,
这个包括了重定向redirect,因为redirect是重新请求一次服务器。
而forward是转发方式,转发不会重新对服务器进行请求所以拦截器就拦截不到。
因为他是服务器部定向,没有重新发请求。。而那两句话就是把重定向跟转发的请求都加入到这个Filter进行处理
不用谢,叫我雷锋