Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top