David David - 2 years ago 357
Java Question

Struts 1 Action Redirect to Struts 2 Action

I have a java webapp with both struts 1 and struts 2. Inside the app there are several Struts 2 namespaces and Struts 1 modules. For example:

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

In my web.xml, the Struts 1 and 2 filters are specifically mapped to the correct namespace/module. For example,



Inside my Struts 1 area, I have a request to have a Struts 1 action forward to a Struts 2 action. I tried the following:

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

However, this results in the following stack trace:

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]

I know that this could be fixed by mapping the Struts 1 parts of the website through the Struts 2 filter, but this causes problems for our specific website and I would like to avoid doing that.

I also tried the action without the module:

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

I got the folowing error:

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

I also tried the following action mapping:

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

I got the following error:

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

So is there anything left that I could try? How do I get a Struts 1 action to return a redirect to a Struts 2 action?

Answer Source

As a workaround, inside my Struts action, I manually modified the response.sendRedirect to send the user to the correct page instead of mapping it inside the struts.xml file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download