我在一个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>





当我点击提交按钮时,我得到带有以下消息的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的错误消息:客户端发送的请求在语法上不正确。
知道发生了什么吗?

谢谢,

问候,
塞班

最佳答案

为什么在answerQuestion方法中有一个snn参数?尝试将其更改为examid

10-04 18:41