消息:此URL不支持HTTP方法POST

时间:2014-11-26 09:50:05

标签: java spring spring-mvc http-post

在有人试图将此标记为重复或由于缺乏研究而标记下来之前我承认这个问题已经存在于堆栈溢出但是提供的解决方案无法解决我的问题所以我想看看人们是否可以解决这个独特的问题我正在经历。

这是我的表格

<form:form method="POST" action="addQuestion" >

   <input type="text" name="questionId" />Enter Id<br>
   <input type="text" name="theQuestion" />Enter Q <br>
   <input type="text" name="category" />Enter Category<br>
   <input type="text" name="correctAnswer" />Enter correct answer<br>
   <input type="submit" value="Next"  >

</form:form>

,这会出现在我的web.xml

<servlet>
        <servlet-name>addQ</servlet-name>
        <servlet-class>main.WebController</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>addQ</servlet-name>
        <url-pattern>/addQuestion</url-pattern>
    </servlet-mapping>

这是我的webcontroller

@RequestMapping("/addQuestion")
        public String addQuestion(ModelMap model, @RequestParam(value="question", required = true)  String theQuestion , @RequestParam(value="questionId", required = true)  Integer questionId, @RequestParam(value="category", required = true)   String category, @RequestParam(value="correctAnswer", required = true)   String correctAnswer) throws SQLException{
            ViewController viewController = new ViewController();
            viewController.createQuestion(questionId, theQuestion, category, correctAnswer);
            model.addAttribute("message", "Hello hope this flipping works");

        return "addQuestion";
    }

我收到的错误消息是此方法不支持HTTP方法POST

1 个答案:

答案 0 :(得分:1)

这样做:

@RequestMapping(value="/addQuestion", method=RequestMethod.POST)