【问题标题】:Is there a standard constant in Java used to refer to HTTP request methods? [duplicate]Java 中是否有用于引用 HTTP 请求方法的标准常量? [复制]
【发布时间】:2010-04-22 00:17:51
【问题描述】:

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

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

【问题讨论】:

    标签: java servlets


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 2015-07-24
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 1970-01-01
      相关资源
      最近更新 更多