king37sniper
king37sniper

Reputation: 1

Struts 2 Actions Redirect

I am using Struts 2.

localhost:8084/Web/viewProductsAction?idProducts=1

After I see this product, I leave a comment.

And it successful but I got moved to

localhost:8084/Web/listProductsAction

Here is code in struts.xml:

<action name="listProductsAction" class="com.struts2.action.ProductsAction" method="viewProducts">
   <result name="success">/products.jsp</result>            
</action>
<action name="sendComments" class="com.struts2.action.CommentsAction" method="sendComments">
   <result name="success" type="redirect">listProductsAction</result>
</action> 

But I want after leave a comment, it forward to

localhost:8084/Web/viewProductsAction?idProducts=1

How can I do that?

Upvotes: 0

Views: 844

Answers (1)

Roman C
Roman C

Reputation: 1

Change the location of the redirect result to redirectAction result and location to viewProductsAction. After the post it will forward to the previous page.

<action name="sendComments" class="com.struts2.action.CommentsAction" method="sendComments">
   <result name="success" type="redirectAction">viewProductsAction?idProducts=1</result>
</action> 

Upvotes: 0

Related Questions