我想知道 Struts 2 核心 jar 是否必须与 Struts2-Json-Plugin jar 同步。因为当我从 Action 类中的方法返回“SUCCESS”时,就会发生异常。我在我的 xml 中将结果类型声明为“json”
<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 是
<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;
}
}