我试图找到一种基于 Java 的结果在 JSP 页面中填充“表单”的方法。
所以这是我的 Javascript 代码:
$('#uSystemList').change(function() {
$.get("/live-application/systemById", {systemid: $("#uSystemList").val()}, displayChangedSystemResults, "html");
});
function displayChangedSystemResults(html){
$('#systemForm').empty();
$('#systemForm').append(html);
}
表格:
<form:form id="systemForm" method="post" action="/live-application/systemSave" commandName="systemForm">
<tr>
<td valign="top"><form:select path="uSystemList" id="uSystemList"> </form:select> </td>
</tr>
<tr>
<td valign="top"><form:input path="fSystemName"/></td>
</tr>
</form:form>
Java方面:
@RequestMapping(value = "/systemById", method = RequestMethod.GET)
public void getSystemById(@RequestParam("systemid") String systemid, OutputStream outputStream) throws IOException {
StringBuilder refreshHtml = new StringBuilder();
try {
String html = new String();
if (!systemid.equals("")) {
System system = service.getSystemById(systemid));
html = html + "<input type='text' value='" + system.getName() + "' id='fSystemName' />";
}
refreshHtml.append(hostHtml);
outputStream.write(refreshHtml.toString().getBytes());
outputStream.flush();
} catch (Exception e) {
outputStream.flush();
}
}
作为测试,我只想填充fSystemName
表单的字段,但是当它返回displayChangedSystemResults
函数时没有任何反应。谁能发现我做错了什么?