Struts 1 Action重定向到Struts 2 Action

时间:2012-05-15 15:02:03

标签: struts2 struts-1

我有一个带有struts 1和struts 2的java webapp。在应用程序内部有几个Struts 2命名空间和Struts 1模块。例如:

/public (Struts 1 module)
/accounting (Struts 2 namespace)
/auditing (Struts 2 namespace)
/receipts (Struts 1 modules)

在我的web.xml中,Struts 1和2过滤器专门映射到正确的命名空间/模块。例如,

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/accounting/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>struts1</filter-name>
    <url-pattern>/public/*</url-pattern>
</filter-mapping>

在我的Struts 1区域内,我有一个请求将Struts 1操作转发到Struts 2操作。我尝试了以下方法:

<action path="/myRedirect" forward="/checkAccountRecords.action" module="accounting" />

但是,这会产生以下堆栈跟踪:

The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

我知道这可以通过Struts 2过滤器映射网站的Struts 1部分来解决,但这会导致我们特定网站的问题,我想避免这样做。

我也尝试了没有模块的动作:

<action path="/myRedirect" forward="/accounting/checkAccountRecords.action" />

我收到了以下错误:

can't find /receipts/accounting/checkAccountRecords.action (file not found)

我还尝试了以下动作映射:

<action path="/myRedirect" forward="../accounting/checkAccountRecords.action" />

我收到以下错误:

Path ../accounting/checkAccountRecords.action does not start with a "/" character

那么还有什么可以尝试的吗?如何获取Struts 1操作以将重定向返回到Struts 2操作?

1 个答案:

答案 0 :(得分:1)

作为一种解决方法,在我的Struts操作中,我手动修改了response.sendRedirect以将用户发送到正确的页面,而不是将其映射到struts.xml文件中。