使用struts2重定向动态参数不起作用

编程入门 行业动态 更新时间:2024-10-24 13:19:32
本文介绍了使用struts2重定向动态参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试使用动态参数重定向映射时遇到问题。

I'm having an issue while trying to redirect mapping with dynamic parameters.

我在Struts2中映射的方式:

<action name="Delete" class="templateLalaAction" method="remove"> <result name="success" type="redirect-action"> <param name="actionName">LalaTemplatesDisplay</param> <param name="buId">${buId}</param> </result> <result name="failure" type="redirect-action"> LalaTemplatesDisplay </result> </action>

操作中的删除方法:

remove() { putRequestAttribute("buId",Long.valueOf("1111")); return SUCCESS; }

如果我这样做,我设置 buId = 1111 ,但是当我运行应用程序时, url 结尾为 buId =(它是空的),即没有传递参数。 如果我评论 putRequestAttribute 方法,并将struts传递 buId 参数作为 static value:

if I do this, I'm setting the buId=1111, but when I run the app, the url ends with buId= (it's empty), i.e., no parameter is being passed. if I comment the putRequestAttribute method, and set struts passing buId parameter as a static value:

<action name="Delete" class="templateLalaAction" method="remove"> <result name="success" type="redirect-action"> <param name="actionName">LalaTemplatesDisplay</param> <param name="buId">1111</param> </result> <result name="failure" type="redirect-action"> LalaTemplatesDisplay </result> </action>

它有效, url 以 buId = 1111 。

我也读过这个问题接受的答案告诉我们做同样的事情,但是如果我们阅读用户所做的评论,我们会看到他有同样的问题我有。我可能做错了什么?

I also read this question where the accepted answer teaches us to do the same I did, but if we read the comments the user did, we'll see he has the same problems I have. What am I possibly doing wrong?

推荐答案

在你的方法中只需分配 buId 变量,你需要在你的动作类中使用getter / setter。

Inside your method just assign buId variable and you need getter/setters for it in your action class.

public String remove() { buId = 1111l; return SUCCESS; }

此外,您使用旧语法 redirect-action ,使用驼峰案例 redirectAction 。

Also you are using old syntax for redirect-action, use camel case redirectAction.

更多推荐

使用struts2重定向动态参数不起作用

本文发布于:2023-10-10 22:37:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479950.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   不起作用   参数   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!