Вопрос

For example, HttpServletResponse has the HTTP status codes as constants like

public static final int SC_OK = 200;
public static final int SC_CREATED = 201;
public static final int SC_BAD_REQUEST = 400;
public static final int SC_UNAUTHORIZED = 401;
public static final int SC_NOT_FOUND = 404;

Is there any such constants defined for HTTP methods like GET, POST, ..., anywhere in the Java EE API so that it could be referenced easily, rather than creating one on my own?

Это было полезно?

Решение

If you are using Spring, you have this enum org.springframework.web.bind.annotation.RequestMethod

public enum RequestMethod {
  GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;
}

EDIT : Here is the complete list of constants values in Java 6 You can see that some of those are available in the class HttpMethod but it contains less values than RequestMethod.

public @interface HttpMethod {
  java.lang.String GET = "GET";
  java.lang.String POST = "POST";
  java.lang.String PUT = "PUT";
  java.lang.String DELETE = "DELETE";
  java.lang.String HEAD = "HEAD";
  java.lang.String OPTIONS = "OPTIONS";

  java.lang.String value();
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top