为什么不支持SpringMVC Request方法’GET’?
我尝试@RequestMapping(value = "/test", method = RequestMethod.POST)
但是错误
代码是
@Controller public class HelloWordController { private Logger logger = LoggerFactory.getLogger(HelloWordController.class); @RequestMapping(value = "/test", method = RequestMethod.POST) public String welcome() { logger.info("Spring params is welcome"); return "/WEB-INF/jsp/welcome"; } }
web.xml是
This is Spring MVC DispatcherServlet SpringMVC DispatchServlet org.springframework.web.servlet.DispatcherServlet SpringContext contextConfigLocation classpath*:springmvc.xml 1
SpringMVC DispatchServlet /
和springmvc.xml是
index.jsp是
<form action="/test" method="post">
我输入提交botton brower是错误
HTTP状态405 – 请求方法’GET’不受支持类型状态报告
消息请求方法’GET’不受支持
description对于请求的资源,不允许使用指定的HTTP方法(不支持请求方法’GET’)。
更改
@RequestMapping(value = "/test", method = RequestMethod.POST)
至
@RequestMapping(value = "/test", method = RequestMethod.GET)
如果您将表单“发布”到url / test,则method = POST
将起作用。
如果您在浏览器的地址栏中键入URL并按Enter键,则它始终是GET
请求,因此您必须指定POST请求。
谷歌的HTTP GET
和HTTP POST
(还有其他几个像PUT DELETE)。 他们都有自己的意思。
我通过在我的控制器中包含get和post请求解决了这个错误:method = {RequestMethod.POST,RequestMethod.GET}
我也有同样的问题。 我将其更改为以下内容并且有效。
Java:
@RequestMapping(value = "/test", method = RequestMethod.GET)
HTML代码:
默认情况下,如果未在表单中指定http方法,则使用GET。 要使用POST方法,您需要明确说明它。
希望这可以帮助。