Where are the request method constants in the Servlet API?

Solution 1:

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

Solution 2:

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.

Solution 3:

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.

Solution 4:

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()