【问题标题】:JSP form: HttpStatus 400: The request sent by the client was syntactically incorrectJSP 形式:HttpStatus 400:客户端发送的请求语法错误
【发布时间】:2016-01-29 21:46:53
【问题描述】:

我在 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 方法中有ssn 参数?尝试将其更改为 examid
  • 你刚刚回答了我的问题!该参数应该被命名为examid!

标签: spring jsp spring-mvc tomcat


【解决方案1】:

为什么 answerQuestion 方法中有一个 ssn 参数?尝试将其更改为考试

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多