开发者

invoke Struts 2 action method with different arguments

In my struts 2 actionclass, I have a method:

public String doXXX(String param){

//do stuff
return SUCCESS;
}

In my config xml, how can I call this method with different values for 'param' based on the action. Something like:

<action name="action1" class="struts2Class" metho开发者_开发技巧d="doXXX" param = "foo" />
<action name="action2" class="struts2Class" method="doXXX" param = "bar" />


You can't pass arguments in the method which you intend to use as the action method. You can specify a param element in the struts.xml for your action as follows:

<action name="action1" class="struts2Class" method="doXXX">
  <param name="foo">bar</param>
</action>

You then need to declare a private variable called foo on your struts2Class with getters and setters. This property will be set when action1 is invoked.

The property foo will be set by the Param Interceptor as part of the action execution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜