日期:2014-05-17  浏览次数:20913 次

struts2 urlrewriter
struts2.16 
urlrewrite-3.2.0

web.xml filter顺序OpenSessionInViewFilter,UrlRewriteFilter,struts2-cleanup,struts2

只要在 <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
去掉<dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>一切正常
加上后
页面中由个别<sx:div>块数据不显示
并且 表单页中的<s:token> java.lang.NullPointerException


------解决方案--------------------
我测试了一下struts2.1中配置<dispatcher>FORWARD </dispatcher> 结果出现StackOverflowError,也许是struts2内部又有FORWARD导致死循环
我认为重写.action即可吧,所以楼主可以这么试一下
XML code
<filter-mapping>
<filter-name>struts2 </filter-name>
<url-pattern>/* </url-pattern>
                <dispatcher>REQUEST </dispatcher>
<dispatcher>FORWARD </dispatcher>

------解决方案--------------------
struts2 还没用过。。。。。 多讨论一些,我也学习一下。
------解决方案--------------------
XML code
<!-- Setting UrlRewriteFilter -->
    <filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>
            org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>  
        <dispatcher>FORWARD</dispatcher> 
    </filter-mapping>
    <!-- 定义整合SiteMesh必须的ActionContextCleanUp Filter -->
    <filter>
        <filter-name>struts-cleanup</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ActionContextCleanUp
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>  
        <dispatcher>FORWARD</dispatcher> 
    </filter-mapping>
    <!-- 定义整合SiteMesh和核心 Filter -->
    <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>*.jsp</url-pattern>
    </filter-mapping>
    <!-- 定义Struts2的FilterDispathcer的Filter -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
    <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <!-- 用于初始化Spring容器的Listener -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>