我试图通过ajax提交一个spring表单,但表单中的值总是为null(实际表单不为null)。
这是我从 JSP 发送表单的方式:
$('#fSystemSave').click(function() {
$.post("/live-application/systemSave", {systemForm: $("#systemForm").serialize()}, displayModifiedSystemResults, "html");
});
这是表格:
<form:form id="systemForm"
method="post" action="/live-application/systemSave"
commandName="systemForm">
<tr>
<td colspan="1" align="left">
<strong>SYSTEM SETTINGS</strong>
</td>
</tr>
<tr>
<td valign="top">Name: </td>
<td valign="top"><form:input path="fName" size="20" /> </td>
</tr>
<tr>
<td valign="top" align="left">
<button type="button" id="fSystemSave">Save</button>
</td>
</tr>
</form:form>
这是 Java Controller 端:
@RequestMapping(value = "/systemSave", method = RequestMethod.POST)
public void saveSystem(@ModelAttribute("systemForm") SystemForm systemForm, OutputStream outputStream) throws IOException {
logger.info("Save System1: " + systemForm);
logger.info("Save System2: " + systemForm.getfName());
}
因此“Save System1”返回一个对象字符串,“Save System2”返回 null。谁能发现我做错了什么吗?
谢谢
最佳答案
我不了解 Spring,但我认为 {systemForm: $("#systemForm").serialize()}
应该是 $("#systemForm").serialize( )
。
关于java - 在 AJax 中提交 Spring 表单始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15208386/