Is there any request method enum in Servlet API? -
this question has answer here:
is there more elegant way that?
if (request.getmethod() == "options") { ... }
i mean there enum
or class
i'm able use in order make reference to?
example:
if (request.getcontenttype().equals(mediatype.application_json)) { ... }
is there more elegant way that?
if (request.getmethod() == "options") { ... }
that's not correct. in java, must use equals()
rather ==
string
comparison:
if ("options".equals(request.getmethod())) { ... }
is there enum or class i'm able use in order make reference to?
in httpservlet
class you'll find constants http methods, private, won't able use them.
if using jax-rs, can use constants defined in httpmethod
. there constants defined delete
, get
, head
, options
, post
, put
methods. jax-rs 2.1, constant patch
available.
Comments
Post a Comment