views:

413

answers:

1

How would I execute a method with an argument in my model based on the URL? Ie, http://server/MyAction_Arg.action maps to MyClass.MyMethod(Arg)? I tried this:

 <action name="MyAction_*" method="MyMethod({1})" class="example.MyClass">
  <result>page.jsp</result>
 </action>

but I get java.lang.NoSuchMethodException at runtime

+1  A: 

In struts2 you can accomplish this like this:

  server/myaction.action?arg=value

And in the MyClass action class you can declare a variable variable named arg with getter and setter. In the MyMethod() method you have access to the value of arg via the getArg() method.

Vincent Ramdhanie
Is this the only way?
Ziplin
No. You can include a form with a hidden field. But it is the most common way of sending data to an action.
Vincent Ramdhanie