【发布时间】:2010-04-22 00:17:51
【问题描述】:
可能重复:
Where are the request method constants in the Servlet API?
我正在寻找一个 Java 字符串常量来引用 HTTP 请求方法(GET、POST、PUT 等)。我希望 HttpServlet 或 HttpServletRequest 具有这些方法的常量,但事实并非如此。
【问题讨论】:
可能重复:
Where are the request method constants in the Servlet API?
我正在寻找一个 Java 字符串常量来引用 HTTP 请求方法(GET、POST、PUT 等)。我希望 HttpServlet 或 HttpServletRequest 具有这些方法的常量,但事实并非如此。
【问题讨论】:
【讨论】:
在Java Spring中,可以使用RequestMapping注解来隔离不同类型的请求方法。它位于以下链接的第 13.11.3 节中: http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-annotation
基本上你可以使用这些注解来获取 HTTP 请求方法类型:
@RequestMapping(method = RequestMethod.GET)
@RequestMapping(method = RequestMethod.POST)
@RequestMapping(method = RequestMethod.PUT)
所有请求类型都在 RequestMethod 对象的枚举中: http://apollo89.com/java/spring-framework-2.5.3/api/org/springframework/web/bind/annotation/RequestMethod.html
【讨论】: