我在jsp中有这个:
<form:form method="POST" modelAttribute="answer">
<table>
<tr>
<td><label for="chosenanswer">answer: </label> </td>
<td>
<form:radiobutton path="chosenAnswer" value="Male" />Male
<form:radiobutton path="chosenAnswer" value="Female" />Female
<form:radiobutton path="chosenAnswer" value="Other" />Other
</td>
</tr>
&#13;
当我点击提交按钮时,我收到一条带有此消息的HTTPStatus 400:
The request sent by the client was syntactically incorrect.
这是我在Controller类中的内容:
@RequestMapping(value = { "/take-exam-{examid}" }, method = RequestMethod.GET)
public String takeExam(@PathVariable String examid, ModelMap model) {
model.addAttribute("answer",new SelectedAnswer());
model.addAttribute("questiontext","Dummy question text");
return "exam";
}
/*
*Answering a question
*/
@RequestMapping(value = { "/take-exam-{examid}" }, method = RequestMethod.POST)
public String answerQuestion(SelectedAnswer answer, BindingResult result,
ModelMap model, @PathVariable String ssn) {
model.addAttribute("answer", "SelectedAnswer: "+answer.toString());
model.addAttribute("success", "SelectedAnswer: "+answer.toString());
return "success";
}
我的SelectedAnswer课程是:
public class SelectedAnswer {
private String chosenAnswer;
public String getChosenAnswer() {
return chosenAnswer;
}
public void setChosenAnswer(String chosenAnswer) {
this.chosenAnswer = chosenAnswer;
}
public String toString()
{
return "SelectedAnswer = "+chosenAnswer;
}
}
页面加载正常,但是当我点击提交按钮时,我得到了HttpStatus 400的错误:客户端发送的请求在语法上是不正确的。 知道发生了什么事吗?
谢谢,
此致 谢尔班
答案 0 :(得分:1)
为什么answerQuestion方法中有ssn参数?试着将其改为考试