Java中是否有用于引用HTTP请求方法的标准常量?

时间:2010-04-22 00:17:51

标签: java servlets

  

可能重复:
  Where are the request method constants in the Servlet API?

我正在寻找一个Java字符串常量来引用HTTP请求方法(GET,POST,PUT等)。我希望HttpServlet或HttpServletRequest有这些方法的常量,但似乎并非如此。

2 个答案:

答案 0 :(得分:8)

答案 1 :(得分:2)

在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