使用struts2重定向动态参数不起作用 [英] Using struts2 to redirect with dynamic parameters not working

查看:414
本文介绍了使用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 以<结尾code> 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重定向动态参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆