I want to write
if (POST.equals(req.getMethod()))
instead of
if (\"POST\".equals(req.getMethod()))
but I
In Spring (so outside JDK, too) you can use:
org.springframework.web.bind.annotation.RequestMethod
This is a enum which provides all HTTP Methods
So you can use RequestMethod.POST.name()
As far as I know, there aren't any constants for that particular property. You can check out the full list of constants to see what is available, though.
Of course, you can always define your own constants if it makes your code easier to write.
It appears that Java EE 6 added the HTTP method names as constants to the javax.ws.rs.HttpMethod annotation interface. Depending on your setup, they may be available to you.
http://docs.oracle.com/javaee/6/api/javax/ws/rs/HttpMethod.html
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.
These constants are defined as private in Servlet,
public abstract class HttpServlet extends GenericServlet
implements java.io.Serializable
{
private static final String METHOD_DELETE = "DELETE";
private static final String METHOD_HEAD = "HEAD";
private static final String METHOD_GET = "GET";
private static final String METHOD_OPTIONS = "OPTIONS";
private static final String METHOD_POST = "POST";
private static final String METHOD_PUT = "PUT";
private static final String METHOD_TRACE = "TRACE";
...
It's perfectly fine just using the method name literally.
Outside of the JDK, Apache Axis has a public constant for POST (but not for any of the other methods):
org.apache.axis.transport.http.HTTPConstants.HEADER_POST