Ayusman
Ayusman

Reputation: 8739

Struts 2 redirect option

All, I want to redirect to an dynamic URL (decided based on certain business rules) and redirect the user from the current page to a page on the redirected URL (same as Servlet redirect).

Say the user is in http://server1:port1/context1/abc.action

on clicking a button, I want to redirect him to

http://server2:port2/context2/xyz.action

how can I achieve that in struts2?

I have tried

<!-- To forward a request to an external EAR -->
<action name="myForward" class="com.test.forwardAction" method="myForward">
  <result name="success" type="redirect-action">${redirectUrl}</result>
  <result name="error" type="tiles">myLoginPage</result>
</action> 

Can you tell me what is the right way of doing this in Struts2?

Thanks

Upvotes: 0

Views: 1468

Answers (2)

James Jithin
James Jithin

Reputation: 10555

Use the Redirect Result type rather than Redirect Action. Please refer the the link below to know more about the Redirect Result. This works on cross domain too.

http://struts.apache.org/2.0.14/docs/redirect-result.html

Upvotes: 1

yoprogramo
yoprogramo

Reputation: 1306

Just compose the redirectUrl in your action (com.test.forwardAction) to point to server2

Upvotes: 0

Related Questions