Where are the request method constants in the Servlet API?

后端 未结 6 745
猫巷女王i
猫巷女王i 2020-12-01 13:33

I want to write

if (POST.equals(req.getMethod()))

instead of

if (\"POST\".equals(req.getMethod()))

but I

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 14:23

    If you wonder why there aren't any enums defined for this, that's explained in this question and answer: Why HttpRequest.HttpMethod is string instead of Enum?

    Bottom line, the HTTP spec does not restrict the set of methods allowed, so additional methods may be used beyond those which are explicitly mentioned in the spec.

提交回复
热议问题