【发布时间】:2016-04-30 17:30:33
【问题描述】:
我是 Spring MVC 的新手。当单击按钮时,我制作了一个简单的表单,表单值发送到控制器并在第二个视图中设置。但是当我点击按钮时,它给了我错误
The request sent by the client was syntactically incorrect.
这是我的代码:
控制器:
@Controller
@RequestMapping(value="/admissionform")
public class StudentAdmissionController {
@RequestMapping(value="/form.html", method = GET)
public ModelAndView getStudentForm() {
ModelAndView model = new ModelAndView("StudentForm");
return model;
}
@RequestMapping(value="/submit.html", method = POST)
public ModelAndView submitStudentForm(@RequestParam("name") String name,
@RequestParam("password") String password) {
ModelAndView model = new ModelAndView("SubmitForm");
model.addObject("msg", "Name is : "+name + " Password is : " + password);
return model;
}
}
学生表格:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Student Form</title>
</head>
<body>
<div class="modal-body" id="main-body">
<form action="submit.html" method="post">
<div>
<label>Email address:</label>
<input class="form-control" id="email" name="email">
</div>
<div >
<label for="pwd">Password:</label>
<input id="pwd" name="password">
</div>
<input type="submit" value="Submit"/>
</form>
</div>
</body>
</html>
提交表格:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Submitted</title>
</head>
<body>
<div>${msg}</div>
</body>
</html>
告诉我我在代码中犯了什么错误。我会很感激的:)
【问题讨论】:
标签: java spring jsp spring-mvc