本文介绍了为什么不支持 SpringMVC 请求方法“GET"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了 @RequestMapping(value = "/test", method = RequestMethod.POST)
但是是错误
I trying @RequestMapping(value = "/test", method = RequestMethod.POST)
but is error
代码是
@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 是
<servlet>
<description>This is Spring MVC DispatcherServlet</description>
<servlet-name>SpringMVC DispatchServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<description>SpringContext</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<servlet-mapping>
<servlet-name>SpringMVC DispatchServlet</servlet-name>
<url-pattern>/</url-pattern>
和 springmvc.xml 是
and springmvc.xml is
index.jsp 是
index.jsp is
<form action="<%=request.getContextPath() %>/test" method="post">
<input type="submit" value="submit">
</form>
我输入提交按钮浏览器出错
I input submit botton brower is error
HTTP 状态 405 - 请求方法GET"不支持的类型状态报告
消息请求方法GET"不支持
message Request method 'GET' not supported
description 指定的 HTTP 方法不允许用于请求的资源(请求方法GET"不是支持).
description The specified HTTP method is not allowed for the requested resource (Request method 'GET' not supported).
推荐答案
更改
@RequestMapping(value = "/test", method = RequestMethod.POST)
到
@RequestMapping(value = "/test", method = RequestMethod.GET)
这篇关于为什么不支持 SpringMVC 请求方法“GET"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!