我有一个JSP页面test.jsp,其中有一个按钮"显示Form"。点击"显示表格"弹出一个表单是一个jsp页面" form.jsp"。
用于验证form.jsp的字段我正在使用Spring验证器。
我想在弹出窗口中提交表单页面并显示相同的" form.jsp"在弹出验证器错误消息的弹出窗口中。任何人都有这方面的消遣吗?
test.jsp的
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function showForm()
{
var requestUrl="${pageContext.request.contextPath}/test/show/form;
try{
$.ajax(
{
type: 'GET',
url: requestUrl,
success: function(data){
$("#dialog_form").html(data);
$("#dialog_form").dialog( "open" );
},
error: function(xhr, ajaxOptions, thrownError){
console.log("Error in displaying rights");
}
});
}catch(e){
console.log("Error in displaying rights");
}
}
</script>
</head>
<body>
<input class="button" value="Show Form" type="button" onClick="showForm();">
<div id="dialog_form"></div>
</body>
</html>
form.jsp
<form:form method="post" commandName="employee" id="employeeForm" action="${pageContext.request.contextPath}/test/submit">
<p>
<label>Name</label>
<span ><form:input path="name" id="nameId" /></span>
<span class="required" id="nameErrors"><form:errors path="name"/></span>
</p>
<p>
<label>Last Name</label>
<span ><form:input path="lastName" id="lastNameId" /></span>
<span class="required" id="lastNameErrors"><form:errors path="lastName"/></span>
</p>
<input class="button" value="Submit" type="submit" id="submitButton">
</form:form>
TestController.java中的
@RequestMapping(value = "/show/form", method = RequestMethod.GET)
public ModelAndView showForm() {
mav = new ModelAndView();
Employee emp = new Employee();
mav.addObject("employee", emp);
mav.setViewName("show_form");
return mav;
}
@RequestMapping(value = "/submit", method = RequestMethod.GET)
public ModelAndView subForm(@ModelAttribut Employee employee, BindingResult result, HttpServletRequest request) {
mav = new ModelAndView();
validator.validate(employee);
mav.addObject("employee", employee);
mav.setViewName("show_form");
return mav;
}