struts 2 + json [英] struts 2 + json

查看:113
本文介绍了struts 2 + json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Struts 2核心jar是否必须与Struts2-Json-Plugin jar同步.因为当我从Action类中的方法返回"SUCCESS"时发生异常.我已经在xml中将结果类型声明为'json'

I want to know that if Struts 2 core jar must be in sync with the Struts2-Json-Plugin jar. because when i am returning 'SUCCESS' from a method in Action class then exception is occurring . ihave declared result type as 'json' in my xml as

<result-type name="json" class="org.apache.struts2.json.JSONResult"/>

我得到的例外是

java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/String;)Ljava/lang/Object;
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:166)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

我正在使用struts2-core-2.0.11.jar,而我的struts.xml是

i am using struts2-core-2.0.11.jar and my struts.xml is

<action name="editEmployee" class="myaction.AddEmployeeAction" method="getValue">
      <result name="success" type="json" />
</action>

我的动作是

public class AddEmployeeAction extends ActionSupport implements ParameterAware {

/**
 * 
 */
private static final long serialVersionUID = 1L;
private EmployeeDaoImp empdao;
private Map parameters;

public EmployeeDaoImp getEmpdao() {
    return empdao;
}

public void setEmpdao(EmployeeDaoImp empdao) {
    this.empdao = empdao;
}

public String getValue() throws Exception
{
    //JSONArray jsonArr = new JSONArray();
    JSONObject jsonObject = new JSONObject();
    String query = getParameterValue("selChar");
    List<String> names = empdao.getData(query);
    /*for (String name : names) {
        jsonArr.add(name);
    }*/
    jsonObject.put("namesList", names);
    return SUCCESS;
}

}

推荐答案

S2插件版本必须与S2版本匹配;插件使用struts2-core提供的机制.

S2 plugin versions must match the S2 version; plugins use mechanisms provided by struts2-core.

尽管插件可以与其他版本的内核一起使用,但绝不会像这样进行测试,因此,除非您提供自己的测试工具,否则无法知道如果您开始随机混合和匹配,行为将是什么.您应该混合搭配.

While a plugin may work with a different version of core, it will never be tested like that, so unless you provide your own test harness, there's no way to know what the behavior will be if you start mixing and matching at random. You should not mix and match.

这篇关于struts 2 + json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆