Здесь я пытаюсь интегрировать Struts 2 с JSON, jQuery и ajax. Он вызывает класс действия, но я не получаю ответ json. Я добавил все JSon плагин и JSON-defult в распорок-XML функциюИнтеграция Struts2 json и ajax не работает
Ajax
function callajax() {
alert(1);
$.getJSON('edituser.action', function(data) {
alert(data);
});
}
класс действий.
package com.hyva.accounts.master.useraccountsetup;
import com.opensymphony.xwork2.ActionSupport;
/**
*
* @author ranjeeth.g
*/
public class MasterUserSetUpActionEdit extends ActionSupport {
private String username = "ranjith";
private String password = "1234";
private String fullname = "Ranjith";
private String emailaddress = "Ranjith";
private String telephone = "8762232246";
@Override
public String execute() {
// System.out.println("session = " + session.isOpen());
return "success";
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getEmailaddress() {
return emailaddress;
}
public void setEmailaddress(String emailaddress) {
this.emailaddress = emailaddress;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
}
Struts-XML
<action name="edituser" class="com.hyva.accounts.master.useraccountsetup.MasterUserSetUpActionEdit">
<result type="json"></result>
</action>
Обновленный код;
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="accounts" namespace="/" extends="hibernate-default,json-default">
<action name="login" class="com.hyva.accounts.userlogin.LoginAction" >
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success">/index.jsp</result>
<result name="error">/login.jsp</result>
<result name="input">/login.jsp</result>
</action>
<action name="edituser" class="com.hyva.accounts.master.useraccountsetup.MasterUserSetUpActionEdit">
<result type="json"></result>
</action>
<action name="userlist" class="com.hyva.accounts.master.useraccountsetup.MasterUserSetUpActionList">
<result name="success">/setup_useracount_list.jsp</result>
</action>
<action name="adduser" class="com.hyva.accounts.master.useraccountsetup.MasterUserSetUpAction">
<interceptor-ref name="jsonValidationWorkflowStack"/>
<result name="input">/setup_useracount_list.jsp</result>
<result name="success">/setup_useracount_list.jsp</result>
</action>
<action name="countryList" method="list" class="com.hyva.accounts.master.country.CountryAction">
<result name="success">/setup_country_list.jsp</result>
</action>
<action name="addCountry" method="saveOrUpdate" class="com.hyva.accounts.country.CountryAction">
<result name="success" type="redirect">countryList</result>
</action>
</package>
</struts>
Если вызов этого URL я получаю
java.lang.NoClassDefFoundError: org/apache/commons/lang/xwork/StringUtils
org.apache.struts2.json.SerializationParams.<init>(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.executeResult(DefaultActionInvocation.java:361)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.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)
Какая ошибка вы получаете – xrcwrn
Я звоню на этот URL-адрес Я получаю http: // localhost: 8088/iAccountsWeb/edituser.action – user4135983
Используйте те же версии для ящиков S2 и плагинов. –