Using struts2 to redirect with dynamic parameters not working

懵懂的女人 提交于 2019-12-23 16:05:55

问题


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

The way I'm mapping in 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>

The method "remove" in the action:

remove() {

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

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>

It works and the url ends with 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?


回答1:


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;
}

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



来源:https://stackoverflow.com/questions/14213967/using-struts2-to-redirect-with-dynamic-parameters-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!