0 0

urlrewriteFilter顺序问题(web.xml)5

urlrewrite中,to的type为redirect就成功,但是地址仍然没有成功伪装。而type=forward就报404错误。估计是web.xml配置顺序问题。(在其他项目urlrewrite是正常的。)请问各位大师,web.xml的配置顺序是怎样的?

我的urlrewrite.xml如下:

<urlrewrite>

<rule>
<note>
主页重定向1
此处redirect类型是可以的,但是下面的forward就报404错误
</note>
<from>^/nav$</from>
    <to type="redirect">%{context-path}/websiteNavigationAction!info_list_page.action?pageName=navIndex</to>
</rule>

<rule>
<note>
主页重定向2
(此处报错404)
</note>
<from>^/navi$</from>
    <to type="forward">%{context-path}/websiteNavigationAction!info_list_page.action?pageName=navIndex</to>
</rule>

<!-- 下面的静态页面也都成功,forward和redirect都行 -->

<rule>
<note>
静态页面1
</note>
<from>^/navIndex$</from>
    <to type="forward">/login.html</to>
</rule>

<rule>
<note>
静态页面2
</note>
<from>^/navIn$</from>
    <to type="redirect">%{context-path}/page/MyHtml.html</to>
</rule>

    <outbound-rule>
<from>/gdpe_web_system/websiteNavigationAction!info_list_page.action?pageName=navIndex</from>
<to type="redirect">^/nav\.html$</to>
</outbound-rule>

</urlrewrite>
===================end1====================

web.xml 文件如下===================

<!-- 顺序为: SetCharacterEncodingFilter、OpenSessionInViewFilter、UrlRewriteFilter、struts2等等-->

<!-- 统一过滤请求字符集 为UTF-8 begin -->
<filter>
<filter-name>setEncoding</filter-name>
<filter-class>com.gdpe.common.util.custom.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>setEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 统一过滤请求字符集 为UTF-8 end -->

<!-- 会员中心访问控制 begin -->
<filter>
<filter-name>memberFolder</filter-name>
<filter-class>com.gdpe.common.util.custom.FilterMemberFolder</filter-class>
</filter>
<filter-mapping>
<filter-name>memberFolder</filter-name>
<url-pattern>/websitePage/Member/Control/*</url-pattern>
</filter-mapping>
<!-- 会员中心访问控制 end -->

<display-name>gdpe</display-name>

<description>gdpe application</description>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>gdpe.root</param-value>
</context-param>

<!-- fresh once every  minutes -->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>

<!--
- Location of the Log4J config file, for initialization and refresh checks.
- Applied by Log4jConfigListener.
-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-base.xml
classpath:applicationContext-plt-action.xml
classpath:applicationContext-plt-dao.xml
classpath:applicationContext-plt-service.xml
classpath:applicationContext-uum-action.xml
classpath:applicationContext-uum-dao.xml
classpath:applicationContext-uum-service.xml
classpath:applicationContext-web-action.xml
classpath:applicationContext-web-dao.xml
classpath:applicationContext-web-service.xml
</param-value>
</context-param>

<!-- OpenSessionInViewFilter =====start -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<!-- 用于处理hibernate session 事务-->
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- OpenSessionInViewFilter =====end -->


<!-- 增加的url重写开始 -->
<filter>
  <filter-name>UrlRewriteFilter</filter-name>
  <filter-class>
   org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
  </filter-class>
  <init-param>
   <param-name>logLevel</param-name>
   <param-value>WARN</param-value>
  </init-param>
</filter>
<filter-mapping>
  <!-- ***** 下面必须要配置 *****  -->
     
  <filter-name>UrlRewriteFilter</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
      <dispatcher>FORWARD</dispatcher>
</filter-mapping>

<!-- 增加的url重写结束  -->



<!-- set before all struts.properties encoding GBK-->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>



<!-- struts2 config -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>


<filter>
<filter-name>CacheFilter</filter-name>
<filter-class>
com.opensymphony.oscache.web.filter.CacheFilter
</filter-class>
<init-param>
<param-name>time</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>scope</param-name>
<param-value>page</param-value>
</init-param>
</filter>


<filter>
<filter-name>GzipJsFilter</filter-name>
<filter-class>com.gdpe.common.filter.GzipJsFilter</filter-class>
<init-param>
<param-name>headers</param-name>
<param-value>Content-Encoding=gzip</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>GzipJsFilter</filter-name>
<url-pattern>*.gzjs</url-pattern>
</filter-mapping>


<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>





<!-- 
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
-->

<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>

<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>

<!--
- Loads the root application context of this web app at startup,
- by default from "/WEB-INF/applicationContext.xml".
- Note that you need to fall back to Spring's ContextLoaderServlet for
- J2EE servers that do not follow the Servlet 2.4 initialization order.
-
- Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
- to access it anywhere in the web application, outside of the framework.
-
- The root context is the parent of all servlet-specific contexts.
- This means that its beans are automatically available in these child contexts,
- both for getBean(name) calls and (external) bean references.
-->

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>

<!-- 在线人数统计 -->
<!--
<listener>
<listener-class>
com.gdpe.common.listener.OnlineCounterListener
</listener-class>
</listener>
-->

<!-- 系统集群初始化 -->
<listener>
<listener-class>
com.gdpe.common.listener.InitSystem
</listener-class>
</listener>

<!-- dwr config star -->
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!--tomcat7 session error-->
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<!-- ******************************************************************************* -->
<!-- 数据库连接池 -->
<!-- ******************************************************************************* -->
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>

<context-param>
<param-name>
org.mortbay.jetty.servlet.ManagedAttributes
</param-name>
<param-value>org.cometd.bayeux,dojox.cometd.bayeux</param-value>
</context-param>

<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>
org.mortbay.cometd.continuation.ContinuationCometdServlet
</servlet-class>
<init-param>
<param-name>filters</param-name>
<param-value>/WEB-INF/filters.json</param-value>
</init-param>
<init-param>
<param-name>timeout</param-name>
<param-value>120000</param-value>
</init-param>
<init-param>
<param-name>interval</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>maxInterval</param-name>
<param-value>10000</param-value>
</init-param>
<init-param>
<param-name>multiFrameInterval</param-name>
<param-value>2000</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>directDeliver</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>refsThreshold</param-name>
<param-value>10</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>


<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

<!-- dwr config end -->

<!-- ckeditor config start -->
<servlet>
<servlet-name>ConnectorServlet</servlet-name>
<servlet-class>
net.fckeditor.connector.ConnectorServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>ConnectorServlet</servlet-name>
<!-- Do not wrap this line otherwise Glassfish will fail to load this file -->
<url-pattern>
/fckeditor/editor/filemanager/connectors/*
</url-pattern>
</servlet-mapping>

<!-- ckeditor config end -->

<!-- filter>
<filter-name>AccessFilter</filter-name>
<filter-class>
com.gdpe.common.filter.AccessControlFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>AccessFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping-->

<error-page>
<error-code>404</error-code>
<location>/websitePage/common/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/websitePage/common/500.jsp</location>
</error-page>
<error-page>
<exception-type>NullPointerException</exception-type>
<location>/websitePage/common/null.jsp</location>
</error-page>

<session-config>
<session-timeout>60</session-timeout>
</session-config>
<!-- 4位验证码 begin -->
<servlet>
<servlet-name>ValidateCodeServlet</servlet-name>
<servlet-class>com.gdpe.common.util.custom.ValidateCodeServlet</servlet-class>
<init-param>
<param-name>width</param-name>
<param-value>72</param-value>
</init-param>
<init-param>
<param-name>height</param-name>
<param-value>28</param-value>
</init-param>
<init-param>
<param-name>codeCount</param-name>
<param-value>4</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ValidateCodeServlet</servlet-name>
<url-pattern>/validateCodeServlet</url-pattern>
</servlet-mapping>
<!-- 4位验证码 end -->
<!-- 会员在线监听 begin -->
<listener>
<listener-class>com.gdpe.common.util.custom.MemberOnlineListener</listener-class>
</listener>
<!-- 会员在线监听 end -->

<distributable />

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>



2013年6月08日 15:51

相关推荐

    urlrewritefilter-2.6.zip(URL重写,重命名)

    将URLRewriteFilter添加到Web应用中,通常需要在`web.xml`中配置Filter,然后指定`urlrewrite.xml`的路径,确保在每个请求之前都会经过URLRewriteFilter。 6. **最佳实践** - 规则的顺序很重要,从上至下执行,...

    超级注意复杂整合环境中的Filter-Mapping的顺序--配置单点登陆及UrlRewrite有感

    在IT行业中,尤其是在Java Web开发领域,我们经常会遇到复杂整合环境下的系统配置问题。这篇博客“超级注意复杂整合环境中的Filter-Mapping的顺序--配置单点登陆及UrlRewrite有感”深入探讨了如何在这样的环境中正确...

    UrlRewriteFilter用法,doc解析实例解析,jar等

    2. **配置web.xml**:在Web应用的`web.xml`配置文件中,添加UrlRewriteFilter的过滤器配置,指定配置文件的位置和过滤器的监听器。 3. **编写配置文件**:创建`urlrewrite.xml`文件,编写URL重写规则。规则通常包括...

    JSP项目的URL重写

    3. **初始化配置**:在`web.xml`文件中配置`urlrewritefilter`,指定配置文件的位置和加载顺序。 4. **测试和调试**:通过浏览器访问应用,观察URL是否按照预期重写。`urlrewritefilter`提供了一些内置的URL以供...

    java urlrewrite解决默认页问题

    - **确保顺序正确:** 在`web.xml`中,URL Rewrite Filter应当配置在Struts Filter之前。 - **测试验证:** 配置完成后,务必进行充分的测试,确保所有链接都能够正确地重定向到目标页面。 - **兼容性考虑:** 不同...

    UrlRewrite实现伪静态

    - **配置web.xml**:然后,在web应用的web.xml中配置UrlRewriteFilter。 ```xml &lt;filter-name&gt;UrlRewriteFilter &lt;filter-class&gt;org.tuckey.web.filters.urlrewrite.UrlRewriteFilter &lt;filter-name&gt;...

    urlrewrite使用

    2. **配置web.xml**:在Web应用的`web.xml`配置文件中,添加URLRewriteFilter的配置,指定filter的类和初始化参数。 3. **编写rewrite.xml**:创建名为`rewrite.xml`的配置文件,放置在Web应用的WEB-INF目录下。在...

    [其他类别]UrlRewriter Java v2.0 RC1_urlrewriterjava.zip

    使用UrlRewriter Java需要在Web应用的配置文件(通常是`web.xml`)中添加过滤器配置,然后创建一个`.xml`配置文件(如`urlrewrite.xml`),在这个文件中编写重写规则。规则通常包含模式匹配、条件检查和重定向或...

    网站安全urlrewrite教程和jar包

    安装并配置`urlrewrite.jar`后,我们需要在Web应用的`web.xml`配置文件中添加`URLRewriteFilter`,然后编写`urlrewrite.xml`规则文件。配置文件的结构通常包括规则集、条件和规则元素,每个规则定义了匹配URL的模式...

    UrlRewrite例子

    通过在web.xml中配置UrlRewriteFilter,我们可以定义一系列规则来转换请求的URL,使得原本复杂的动态URL变得简洁易读。 Struts2是一个流行的MVC框架,它的Action机制允许开发者通过不同的URL来调用不同的业务逻辑。...

    URL过滤.doc

    2. **顺序问题**:URL重写规则的执行顺序很重要,优先级高的规则会先被执行。 3. **调试与测试**:配置完成后,建议进行详细的测试以确保URL重写按预期工作。 #### 五、总结 本文详细介绍了如何在Struts2框架中...

Global site tag (gtag.js) - Google Analytics