Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 请求方法';邮政';Spring mvc中不支持_Spring Mvc_Httprequest_Httpresponse_Http Response Codes - Fatal编程技术网

Spring mvc 请求方法';邮政';Spring mvc中不支持

Spring mvc 请求方法';邮政';Spring mvc中不支持,spring-mvc,httprequest,httpresponse,http-response-codes,Spring Mvc,Httprequest,Httpresponse,Http Response Codes,这是我的表格: <form action="${pageContext.request.contextPath}/admin/editc" method="POST" id="editForm"> <input type="text" name="username" class="form-control" /> <input type="text" name="password" class="form-control" /> <

这是我的表格:

<form action="${pageContext.request.contextPath}/admin/editc" method="POST" id="editForm">
    <input type="text" name="username" class="form-control" />
    <input type="text" name="password" class="form-control" />
    <input type="submit" value="submit" >
</form>
现在的问题是,我在控制台中遇到405错误,如下所示:

org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
 WARNING: Request method 'POST' not supported

有谁能帮我解决这个错误吗?

您的java方法的签名是错误的,您需要添加您在帖子中期望的内容。查看此文档以更正代码

首先需要一个GET方法来显示表单,然后需要一个POST来提交表单

@RequestMapping(value = "/admin/editc", method = RequestMethod.GET)
public ModelAndView updateCredentials() {
    return new ModelAndView("editPage");
}

@RequestMapping(value = "/admin/editc", method = RequestMethod.POST)
public ModelAndView updateCredentials(@ModelAttribute UserCredentials credentials) {
    someService.save(credentials);
    ...
}

嗨@Damien重新检查问题我有Get方法。但是你的post方法不包含任何属性值。您的表单将尝试找到一个处理程序,该处理程序采用您模式中的结构,就像我的示例中的UserCredentials对象将包含用户名和密码字符串字段。即使我添加了用户名和密码,这意味着它不起作用,但我通过删除这些参数进行了测试。您是指@ModelAttribute(…)注释@daniele。我以前有过它,但当时它不起作用,我的意思是@damien答案的相同签名,而且你应该为GET添加另一个处理程序。请注意,对于POST处理程序,您需要接受包含formIt字段的类的参数,但将model属性作为控制器方法的参数并不一定为true。是的,我同意您的看法@minionI在发布的代码中没有发现任何错误。有些事情出了问题。很难说哪里可能是错的。为了进一步调试,get调用工作正常吗?如果是这样,当服务器启动时,它将吐出请求映射的详细信息。检查映射是否绑定到控制器。
@RequestMapping(value = "/admin/editc", method = RequestMethod.GET)
public ModelAndView updateCredentials() {
    return new ModelAndView("editPage");
}

@RequestMapping(value = "/admin/editc", method = RequestMethod.POST)
public ModelAndView updateCredentials(@ModelAttribute UserCredentials credentials) {
    someService.save(credentials);
    ...
}