我重写的链接中有大约 30 个工作正常,但我有几个第一次调用时不起作用,但第二次调用时确实起作用!
这是 web.xml 片段:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>uk.co.prodia.prosoc.struts2.action</param-value>
</init-param>
</filter>
<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>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
这是 urlrewrite.xml 第一次调用时给出 404:
<rule>
<from>^/forgotten-password$</from>
<to>/unsecured/forgotten-password!input.action</to>
</rule>
以及该操作的 struts2 配置:
<package name="unsecured" extends="struts-default" namespace="/unsecured">
<action name="forgotten-password" class="actionForgottenPassword">
<result name="input">/WEB-INF/view/unsecured/forgotten-password.jsp</result>
<result name="passwordNotFound">/WEB-INF/view/unsecured/forgotten-password.jsp</result>
</action>
</package>
但是,如果我让 urlrewrite.xml 通过unsecured
包含forgotten-password
操作的包,那么它可以工作:
<rule>
<from>^/unsecured/forgotten-password$</from><!--works through /unsecured -->
<to>/unsecured/forgotten-password!input.action</to>
</rule>
似乎 urlrewrite 中缺少 Struts2 包名称会导致第一次使用 URI 时出现 404。
这对任何人都有意义吗,还是我应该留在疯狂的小镇?