Struts2 json和ajax集成不起作用

Struts2 json和ajax集成不起作用,struts2,struts2-jquery,struts2-json-plugin,Struts2,Struts2 Jquery,Struts2 Json Plugin,在这里,我尝试将Struts 2与JSON、jQuery和ajax集成,它正在调用action类,但我没有得到JSON响应。我在StrutsXML中添加了所有json插件和json函数 Ajax函数 函数callajax(){ 警报(1); $.getJSON('edituser.action',函数(数据){ 警报(数据); }); } 动作类。 package com.hyva.accounts.master.useraccountsetup; 导入com.opensymphony.xwo

在这里,我尝试将Struts 2与JSON、jQuery和ajax集成,它正在调用action类,但我没有得到JSON响应。我在StrutsXML中添加了所有json插件和json函数

Ajax函数

函数callajax(){
警报(1);
$.getJSON('edituser.action',函数(数据){
警报(数据);
});
}
动作类。

package com.hyva.accounts.master.useraccountsetup;
导入com.opensymphony.xwork2.ActionSupport;
/**
*
*@author ranjeeth.g
*/
公共类MasterUserSetUpActionEdit扩展了ActionSupport{
私有字符串username=“ranjith”;
私有字符串密码=“1234”;
私有字符串fullname=“Ranjith”;
私有字符串emailaddress=“Ranjith”;
专用字符串电话=“8762232246”;
@凌驾
公共字符串execute(){
//System.out.println(“session=“+session.isOpen());
返回“成功”;
}
公共字符串getUsername(){
返回用户名;
}
public void setUsername(字符串用户名){
this.username=用户名;
}
公共字符串getPassword(){
返回密码;
}
public void setPassword(字符串密码){
this.password=密码;
}
公共字符串getFullname(){
返回全名;
}
public void setFullname(字符串fullname){
this.fullname=fullname;
}
公共字符串getEmailaddress(){
返回电子邮件地址;
}
public void setEmailaddress(字符串emailaddress){
this.emailaddress=电子邮件地址;
}
公共字符串getTelephone(){
回电;
}
公用电话(串电话){
这个电话;
}
}
StrutsXML


更新代码


/index.jsp
/login.jsp
/login.jsp
/setup\u useracount\u list.jsp
/setup\u useracount\u list.jsp
/setup\u useracount\u list.jsp
/setup\u country\u list.jsp
国家名单
如果我收到对该url的呼叫

java.lang.NoClassDefFoundError:org/apache/commons/lang/xwork/StringUtils
SerializationParams.java:57
org.apache.struts2.json.JSONResult.writeToResponse(JSONResult.java:214)
org.apache.struts2.json.JSONResult.execute(JSONResult.java:204)
com.opensymphony.xwork2.DefaultActionInvocation.ExecuteSult(DefaultActionInvocation.java:361)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
com.opensymphony.xwork2.intercept.DefaultWorkflowIntercept.doIntercept(DefaultWorkflowIntercept.java:163)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
1)根据您的struts2版本从

2) 您的包应该扩展
json默认值
,如下所示

<package name="example1" extends="struts-default, json-default">
<action name="edituser" class="com.hyva.accounts.master.useraccountsetup.MasterUserSetUpActionEdit">
            <result type="json"></result>
   </action>
</package>

3) 检查您的操作是否有json结果,如地址bas中的操作名称
http://localhost:8080/edituser


它将显示对浏览器的json响应。

包括Apache的
commons-lang-2.x.jar

然后,由于2.1.8中发生了重大变化,请注意,将2.1.6与2.1.8混合使用是非常非常糟糕的

对所有struts库使用相同的版本。Struts核心、Struts json、其他(如果有的话)(Struts spring插件、Struts配置浏览器插件、Struts junit插件等)。除了struts jquery插件、frremarker和ognl(顺便说一句,必须根据中指定的正确版本选择该版本)之外的所有其他版本


然后,由于安全问题(以及其他原因),尝试升级到最新版本(2.3.16.3)是非常重要的。如果您要这样做,那么就同时包括Apache的
commons-lang-2.x.jar
和Apache的
commons-lang3-3.x.jar
(如果由于遗留代码,只有后者还不够的话)。因为它们在不同的包中,所以它们可以一致存在。

感谢您的重播,这就是我使用的struts2-core-2.1.6.jar和struts2-json-plugin-2.1.8.1.jar,我已经更新了我的代码,请查看上面的内容。您遇到了什么错误我调用此url,我使用的是S2-core和plugin-jar的相同版本。