尝试使用动态参数重定向映射时遇到问题。
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重定向动态参数不起作用
发布评论