我正在尝试通过 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 控制器端:
@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'返回一个Object tostring,'Save System2'返回null。谁能发现我做错了什么?
谢谢,