В проекте Struts1 я пытаюсь отправить ajax,
полезная нагрузка запроса chrome в порядке {"account": "abcd", "pwd": "1234"}
но в debugMode все значения actionForm полностью нулевые.
область Ajax:
function loging() {
alert(getFormData());
$.ajax({
url : '${pageContext.request.contextPath}/hello.do?method=jsonHi',
type : 'POST',
data : getFormData(),
contentType : 'application/json',
dataType : 'json',
async:false,
success : function(data) {
alert("success");
},
error : function() {
alert("error!");
}
});
}
function getFormData() {
return JSON.stringify({
'account' : $("#account").val(),
'pwd' : $("#pwd").val()
});
};
область настроек Struts:
<struts-config>
<form-beans>
<form-bean name="formClass" type="com.pete.form.AccountForm" />
</form-beans>
<action-mappings>
<action name="formClass" path="/hello" parameter="method" type="com.pete.action.HelloAction" scope="request" validate="false">
<forward name="helloUser" path="/WEB-INF/pages/hello.jsp" />
<forward name="jsonHi" path="/WEB-INF/pages/afterAjax.jsp"/>
</action>
</action-mappings>
область формы:
public class AccountForm extends ActionForm{
private static final long serialVersionUID = -7462505002509046403L;
private String account = null;
private String pwd= null;
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}
Область действия:
public class HelloAction extends DispatchAction {
public ActionForward jsonHi(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
AccountForm reqForm = (AccountForm) form;
System.out.println(reqForm.getAccount());//console is null
System.out.println(reqForm.getPwd());// console is null
return null;
}
}
Я не знаю, что происходит, значения формы равны нулю