user1752078
user1752078

Reputation: 95

Calling method with arguments in struts 2?

I have a method given below in struts 2 action class;

 public String add(String boo){
//codes here
    }

I want to call the add method. And my struts.xml

<action name="Login" class="com.json.action.JsonAction" method="add">
        <param name="boo">boo</param>
                <result name="success">/success.jsp</result>
        </action>

And it shows an error like java.lang.NoSuchMethodException: com.json.action.JsonAction.add(). How can i call the add method?

Upvotes: 3

Views: 6339

Answers (2)

Aleksandr M
Aleksandr M

Reputation: 24396

You cannot declare action method with arguments. But you can create variable inside your action class with getters and setters. Read about action configuration in Struts2 https://struts.apache.org/core-developers/action-configuration.html.

Upvotes: 1

mmalmeida
mmalmeida

Reputation: 1057

Struts actions do not have parameters and return a String.

What you want to do is have a String boo in your action class with getter/setters. It will then be available in your method. And if you have the default interceptor stack (see http://struts.apache.org/2.2.3/docs/interceptors.html) it will automatically be populated with "boo" according to your struts.xml configuration.

Upvotes: 1

Related Questions