javax.servlet.ServletRequest interface to provide
request information for HTTP servlets.
The servlet container creates an HttpServletRequest
object and passes it as an argument to the servlet's service
methods (doGet, doPost, etc).
| Modifier and Type | Field and Description |
|---|---|
| public static final String | BASIC_AUTH
String identifier for Basic authentication. |
| public static final String | CLIENT_CERT_AUTH
String identifier for Client Certificate authentication. |
| public static final String | DIGEST_AUTH
String identifier for Digest authentication. |
| public static final String | FORM_AUTH
String identifier for Form authentication. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true when non-null values were or have been
established as the values returned by getUserPrincipal,
getRemoteUser, and getAuthType. Return
false if authentication is incomplete and the underlying
login mechanism has committed, in the response, the message (e.g.,
challenge) and HTTP status code to be returned to the user.The response)HttpServletResponse
associated with this HttpServletRequestUse the container login mechanism configured for the
|
| public String | Returns: the new session idChange the session id of the current session associated with this request and return the new session id. |
| public String | Returns: one of the static members BASIC_AUTH, FORM_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH (suitable for == comparison) or the container-specific string indicating the authentication scheme, ornull if the request was
not authenticated.Returns the name of the authentication scheme used to protect the servlet. |
| public String | Returns: aString specifying the
portion of the request URI that indicates the context
of the requestReturns the portion of the request URI that indicates the context of the request. |
| public Cookie[] | Returns: an array of all theCookies
included with this request, or null
if the request has no cookiesReturns an array containing all of the |
| public long | Returns: along value
representing the date specified
in the header expressed as
the number of milliseconds
since January 1, 1970 GMT,
or -1 if the named header
was not included with the
requesta name)String specifying the
name of the headerReturns the value of the specified request header
as a |
| public String | |
| public Enumeration | Returns: an enumeration of all the header names sent with this request; if the request has no headers, an empty enumeration; if the servlet container does not allow servlets to use this method,nullReturns an enumeration of all the header names this request contains. |
| public Enumeration | Returns: anEnumeration containing
the values of the requested header. If
the request does not have any headers of
that name return an empty
enumeration. If
the container does not allow access to
header information, return nulla name)String specifying the
header nameReturns all the values of the specified request header
as an |
| public default HttpServletMapping | Returns: An instance ofHttpServletMapping describing the manner in which
the current request was invoked.Return the |
| public int | Returns: an integer expressing the value of the request header or -1 if the request doesn't have a header of this namea name)String specifying the name
of a request headerReturns the value of the specified request header
as an |
| public String | Returns: aString
specifying the name
of the method with which
this request was madeReturns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. |
| public Part | |
| public Collection | |
| public String | Returns: aString, decoded by the
web container, specifying
extra path information that comes
after the servlet path but before
the query string in the request URL;
or null if the URL does not have
any extra path informationReturns any extra path information associated with the URL the client sent when it made this request. |
| public String | Returns: aString specifying the
real path, or null if
the URL does not have any extra path
informationReturns any extra path information after the servlet name but before the query string, and translates it to a real path. |
| public String | Returns: aString containing the query
string or null if the URL
contains no query string. The value is not
decoded by the container.Returns the query string that is contained in the request URL after the path. |
| public String | Returns: aString specifying the login
of the user making this request, or null
if the user login is not knownReturns the login of the user making this request, if the
user has been authenticated, or |
| public String | Returns: aString specifying the session
ID, or null if the request did
not specify a session IDReturns the session ID specified by the client. |
| public String | Returns: aString containing
the part of the URL from the
protocol name up to the query stringReturns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. |
| public StringBuffer | Returns: aStringBuffer object containing
the reconstructed URLReconstructs the URL the client used to make the request. |
| public String | Returns: aString containing
the name or path of the servlet being
called, as specified in the request URL,
decoded, or an empty string if the servlet
used to process the request is matched
using the "/*" pattern.Returns the part of this request's URL that calls the servlet. |
| public HttpSession | Returns: theHttpSession associated
with this request or null if
create is false
and the request has no valid sessiontrue to create
a new session for this request if necessary;
false to return null
if there's no current sessionReturns the current |
| public HttpSession | Returns: theHttpSession associated
with this requestReturns the current session associated with this request, or if the request does not have a session, creates one. |
| public default Map | Returns: A map of trailer fields in which all the keys are in lowercase, regardless of the case they had at the protocol level. If there are no trailer fields, yetisTrailerFieldsReady is returning true,
the empty map is returned.Get the request trailer fields. |
| public Principal | Returns: ajava.security.Principal containing
the name of the user making this request;
null if the user has not been
authenticatedReturns a |
| public boolean | Returns: true if the session ID
was conveyed to the server an an HTTP
cookie; otherwise, falseChecks whether the requested session ID was conveyed to the server as an HTTP cookie. |
| public boolean | Returns: true if the session ID was conveyed to the
server as part of a URL; otherwise,
falseChecks whether the requested session ID was conveyed to the server as part of the request URL. |
| public boolean | Returns: true if the session ID was conveyed to the
server as part of a URL; otherwise,
false
Deprecated
As of Version 2.1 of the Java Servlet
API, use
isRequestedSessionIdFromURL
instead.
|
| public boolean | Returns: true if this
request has an id for a valid session
in the current session context;
false otherwiseChecks whether the requested session ID is still valid. |
| public default boolean | Returns: a boolean whether trailer fields are ready to readReturn a boolean indicating whether trailer fields are ready to read
using |
| public boolean | Returns: aboolean indicating whether
the user making this request belongs to a given role;
false if the user has not been
authenticateda role)String specifying the name
of the roleReturns a boolean indicating whether the authenticated user is included in the specified logical "role". |
| public void | login(String
The username, String String value corresponding to
the login identifier of the user.The password password)String corresponding
to the identified user.Validate the provided username and password in the password validation
realm used by the web container login mechanism configured for the
|
| public void | logout()
Establish |
| public default PushBuilder | Returns: aPushBuilder for issuing server push responses
from the current request, or null if push is not supportedInstantiates a new instance of |
| public <T extends HttpUpgradeHandler> T |
| BASIC_AUTH | back to summary |
|---|---|
| public static final String BASIC_AUTH String identifier for Basic authentication. Value "BASIC" | |
| CLIENT_CERT_AUTH | back to summary |
|---|---|
| public static final String CLIENT_CERT_AUTH String identifier for Client Certificate authentication. Value "CLIENT_CERT" | |
| DIGEST_AUTH | back to summary |
|---|---|
| public static final String DIGEST_AUTH String identifier for Digest authentication. Value "DIGEST" | |
| FORM_AUTH | back to summary |
|---|---|
| public static final String FORM_AUTH String identifier for Form authentication. Value "FORM" | |
| authenticate | back to summary |
|---|---|
| public boolean authenticate(HttpServletResponse response) throws IOException, ServletException Use the container login mechanism configured for the
This method may modify and commit the argument
| |
| changeSessionId | back to summary |
|---|---|
| public String changeSessionId() Change the session id of the current session associated with this request and return the new session id.
| |
| getAuthType | back to summary |
|---|---|
| public String getAuthType() Returns the name of the authentication scheme used to protect
the servlet. All servlet containers support basic, form and client
certificate authentication, and may additionally support digest
authentication.
If the servlet is not authenticated Same as the value of the CGI variable AUTH_TYPE.
| |
| getContextPath | back to summary |
|---|---|
| public String getContextPath() Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string. It is possible that a servlet container may match a context by
more than one context path. In such cases this method will return the
actual context path used by the request and it may differ from the
path returned by the
| |
| getCookies | back to summary |
|---|---|
| public Cookie[] getCookies() Returns an array containing all of the
| |
| getDateHeader | back to summary |
|---|---|
| public long getDateHeader(String name) Returns the value of the specified request header
as a The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive. If the request did not have a header of the
specified name, this method returns -1. If the header
can't be converted to a date, the method throws
an
| |
| getHeader | back to summary |
|---|---|
| public String getHeader(String name) Returns the value of the specified request header
as a | |
| getHeaderNames | back to summary |
|---|---|
| public Enumeration Returns an enumeration of all the header names this request contains. If the request has no headers, this method returns an empty enumeration. Some servlet containers do not allow
servlets to access headers using this method, in
which case this method returns
| |
| getHeaders | back to summary |
|---|---|
| public Enumeration Returns all the values of the specified request header
as an Some headers, such as If the request did not include any headers
of the specified name, this method returns an empty
| |
| getHttpServletMapping | back to summary |
|---|---|
| public default HttpServletMapping getHttpServletMapping() Return the The returned object is immutable. Servlet 4.0 compliant implementations must override this method. Implementation Specification The default implementation returns a
| |
| getIntHeader | back to summary |
|---|---|
| public int getIntHeader(String name) Returns the value of the specified request header
as an The header name is case insensitive.
| |
| getMethod | back to summary |
|---|---|
| public String getMethod() Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. Same as the value of the CGI variable REQUEST_METHOD.
| |
| getPart | back to summary |
|---|---|
| public Part getPart(String name) throws IOException, ServletException Gets the
| |
| getParts | back to summary |
|---|---|
| public Collection Gets all the If this request is of type Any changes to the returned
| |
| getPathInfo | back to summary |
|---|---|
| public String getPathInfo() Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a "/" character. This method returns Same as the value of the CGI variable PATH_INFO.
| |
| getPathTranslated | back to summary |
|---|---|
| public String getPathTranslated() Returns any extra path information after the servlet name but before the query string, and translates it to a real path. Same as the value of the CGI variable PATH_TRANSLATED. If the URL does not have any extra path information,
this method returns
| |
| getQueryString | back to summary |
|---|---|
| public String getQueryString() Returns the query string that is contained in the request
URL after the path. This method returns
| |
| getRemoteUser | back to summary |
|---|---|
| public String getRemoteUser() Returns the login of the user making this request, if the
user has been authenticated, or
| |
| getRequestedSessionId | back to summary |
|---|---|
| public String getRequestedSessionId() Returns the session ID specified by the client. This may
not be the same as the ID of the current valid session
for this request.
If the client did not specify a session ID, this method returns
| |
| getRequestURI | back to summary | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public String getRequestURI() Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this String. For example:
To reconstruct an URL with a scheme and host, use
| ||||||||||||
| getRequestURL | back to summary |
|---|---|
| public StringBuffer getRequestURL() Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters. If this request has been forwarded using
Because this method returns a This method is useful for creating redirect messages and for reporting errors.
| |
| getServletPath | back to summary |
|---|---|
| public String getServletPath() Returns the part of this request's URL that calls the servlet. This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT_NAME. This method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.
| |
| getSession | back to summary |
|---|---|
| public HttpSession getSession(boolean create) Returns the current If To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity and is asked to create a new session when the response is committed, an IllegalStateException is thrown.
| |
| getSession | back to summary |
|---|---|
| public HttpSession getSession() Returns the current session associated with this request, or if the request does not have a session, creates one.
| |
| getTrailerFields | back to summary |
|---|---|
| public default Map Get the request trailer fields. The returned map is not backed by the
Implementation Specification The default implementation returns an empty map.
| |
| getUserPrincipal | back to summary |
|---|---|
| public Principal getUserPrincipal() Returns a
| |
| isRequestedSessionIdFromCookie | back to summary |
|---|---|
| public boolean isRequestedSessionIdFromCookie() Checks whether the requested session ID was conveyed to the server as an HTTP cookie.
| |
| isRequestedSessionIdFromURL | back to summary |
|---|---|
| public boolean isRequestedSessionIdFromURL() Checks whether the requested session ID was conveyed to the server as part of the request URL.
| |
| isRequestedSessionIdFromUrl | back to summary |
|---|---|
| public boolean isRequestedSessionIdFromUrl()
Deprecated As of Version 2.1 of the Java Servlet
API, use
| |
| isRequestedSessionIdValid | back to summary |
|---|---|
| public boolean isRequestedSessionIdValid() Checks whether the requested session ID is still valid. If the client did not specify any session ID, this method returns
| |
| isTrailerFieldsReady | back to summary |
|---|---|
| public default boolean isTrailerFieldsReady() Return a boolean indicating whether trailer fields are ready to read
using
Implementation Specification The default implementation returns false.
| |
| isUserInRole | back to summary |
|---|---|
| public boolean isUserInRole(String role) Returns a boolean indicating whether the authenticated user is included
in the specified logical "role". Roles and role membership can be
defined using deployment descriptors. If the user has not been
authenticated, the method returns The role name "*" should never be used as an argument in calling
| |
| login | back to summary |
|---|---|
| public void login(String username, String password) throws ServletException Validate the provided username and password in the password validation
realm used by the web container login mechanism configured for the
This method returns without throwing a When this method returns without throwing an exception, it must
have established non-null values as the values returned by
| |
| logout | back to summary |
|---|---|
| public void logout() throws ServletException Establish
| |
| newPushBuilder | back to summary |
|---|---|
| public default PushBuilder newPushBuilder() Instantiates a new instance of Implementation Specification The default implementation returns null.
| |
| upgrade | back to summary |
|---|---|
| public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException Creates an instance of
| |