Jquery plugins struts2 jquery插件+;struts2 json插件:在同一个动作类中是否可能有许多json getter方法?

Jquery plugins struts2 jquery插件+;struts2 json插件:在同一个动作类中是否可能有许多json getter方法?,jquery-plugins,struts2,jsonplugin,Jquery Plugins,Struts2,Jsonplugin,我的问题是:如果使用struts2 jquery plugin+struts2 json plugin,我可以定义很多函数吗 @Actions( { @Action(value = "/func1", results = { @Result(name = "str1", type = "json") }) }) public String func1(){ //instructions return "str1"; } @

我的问题是:如果使用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";
}
public String getJSON1()
{
  func1();
}
public String getJSON2()
{
  return func2();
}
还有许多JSON方法获取程序,例如:

@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";
}
public String getJSON1()
{
  func1();
}
public String getJSON2()
{
  return func2();
}
在同一个动作课上


事先非常感谢。

我以前也试过,但没用。但我设计了一个解决办法,也许对你有用。解决方法将参数传递给操作。e、 g

动作类

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> 

芬登
芬德卡斯特

我不明白目标是什么。getJSONn函数与action方法有什么关系?我想他是说GetJSON方法就是actions。是的,您可以有多个返回json的操作方法。这往往会出现具有相同搜索参数的FindEmployees、FindCustomers和FindSuppliers。然而,将多个操作的通用性移动到它自己的setter中,使用string或更好的enum,然后返回到一个操作,这样做更有意义。