简体   繁体   中英

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?

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM