我的问题是:在使用struts2-jquery-plugin+struts2-json-plugin的情况下,我可以定义许多函数,例如:
@Actions( {
@Action(value = "/func1", results = {
@Result(name = "str1", type = "json")
})
})
public String func1(){
//instructions
return "str1";
}
@Actions( {
@Action(value = "/func2", results = {
@Result(name = "str2", type = "json")
})
})
public String func2(){
//instructions
return "str2";
}
和许多 JSON 方法获取者,例如:
public String getJSON1()
{
func1();
}
public String getJSON2()
{
return func2();
}
在同一个动作类中?
提前非常感谢你。
我过去尝试过,但没有用。但是我设计了一个解决方法,也许对您有用。解决方法将参数传递给操作。
操作类
private String jsonMethod;
//getters and setters
public String getJSON()
{
if(jsonMethod.equals("findEmp"))
{
}else if(jsonMethod.equals("findCust"))
{
}
return SUCCESS;
}
从您的 JSP
<s:url id="findEmp" namespace="/" action="getJSON" >
<s:param name="jsonMethod">findEmp</s:param>
</s:url>
<s:url id="findCust" namespace="/" action="getJSON" >
<s:param name="jsonMethod">findCust</s:param>
</s:url>