在struts 2中使用参数调用方法? [英] Calling method with arguments in struts 2?
问题描述
我在struts 2动作类中有一个下面给出的方法;
I have a method given below in struts 2 action class;
public String add(String boo){
//codes here
}
我想调用 add 方法.还有我的 struts.xml
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>
它显示了一个错误,如java.lang.NoSuchMethodException: com.json.action.JsonAction.add().如何调用 add 方法?
And it shows an error like java.lang.NoSuchMethodException: com.json.action.JsonAction.add(). How can i call the add method?
推荐答案
Struts 动作没有参数并返回一个字符串.
Struts actions do not have parameters and return a String.
你想要做的是在你的动作类中有一个带有 getter/setter 的 String boo.然后它将在您的方法中可用.如果您有默认的拦截器堆栈(请参阅 http://struts.apache.org/2.2.3/docs/interceptors.html) 它将根据您的 struts.xml 配置自动填充boo".
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.
这篇关于在struts 2中使用参数调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!