【问题标题】:Struts 2 Actions RedirectStruts 2 动作重定向
【发布时间】:2015-02-18 08:19:20
【问题描述】:

我正在使用 Struts 2。

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

我该怎么做?

【问题讨论】:

  • 上述网址的动作配置是什么?
  • 你的意思是 web.xml 文件?
  • 您仅在 xml 中发布了两个操作 listProductsActionsendComments 的操作配置。 localhost:8084/Web/viewProductsAction?idProducts=1的动作配置是什么?
  • /products.jsp行动>

标签: java redirect struts2 actionresult


【解决方案1】:

redirect 结果的位置更改为redirectAction 结果并将位置更改为viewProductsAction。发帖后会跳转到上一页。

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

【讨论】:

  • 带参数试试
  • 我卡在了这一点上,如何在struts.xml文件中使用参数
  • 我尝试了,但它不起作用。 &lt;action name="sendComments" class="com.struts2.action.CommentsAction" method="sendComments"&gt; &lt;param name="idProducts"&gt;${idProducts}&lt;/param&gt; &lt;result name="success" type="redirectAction"&gt;viewProductsAction?&lt;/result&gt; &lt;/action&gt;
  • 好的,我明天试试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-16
  • 1970-01-01
相关资源
最近更新 更多