为什么不支持SpringMVC请求方法“GET”?
2022-09-01 11:48:32
我已尝试,但存在错误@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";
}
}
网络.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 是
索引.jsp是
<form action="<%=request.getContextPath() %>/test" method="post">
<input type="submit" value="submit">
</form>
我输入提交 botton 浏览器错误
HTTP 状态 405 - 请求方法“GET”类型不支持状态报告
不支持消息请求方法“GET”
说明 请求的资源不允许使用指定的 HTTP 方法(不支持请求方法“GET”)。