【发布时间】:2011-03-21 00:03:44
【问题描述】:
我尝试@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 是
<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是
index.jsp 是
<form action="<%=request.getContextPath() %>/test" method="post">
<input type="submit" value="submit">
</form>
我输入提交按钮浏览器出错
HTTP 状态 405 - 请求方法“GET” 不支持类型状态报告
消息请求方法'GET'不 支持
description 指定的HTTP方法 不允许请求的 资源(请求方法 'GET' 不是 支持)。
【问题讨论】:
-
在welcome()方法中看到日志信息了吗?
-
我还不清楚如何解决这个问题,这里没有好的答案。没有人解释为什么我们不能做 RequestMethod.POST。有人可以跟进吗?我不懂任何cmets。
标签: java spring spring-mvc