Struts 2动作重定向

时间:2014-12-19 11:38:52

标签: java struts2

我正在使用Struts2。

localhost:8084/Web/viewProductsAction?idProducts=1

在看到此产品后,我发表评论

它成功但我被转移到localhost:8084/Web/listProductsAction

以下是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> 

但是我想在发表评论后转发localhost:8084/Web/viewProductsAction?idProducts=1

我该怎么做?

1 个答案:

答案 0 :(得分:0)

redirect结果的位置更改为redirectAction结果和位置viewProductsAction。发布后,它将转发到上一页。

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