jakarta.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 if the user is successfully authenticated and false if notThe response to use to return any authentication challenge response)Triggers the same authentication process as would be triggered if the request is for a resource that is protected by a security constraint. |
| public String | Returns: the new session ID allocated to the sessionChanges the session ID of the session associated with this request. |
| 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: the mapping information for this requestObtain the mapping information for this request. |
| 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, canonicalized 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, canonicalized by the web container, containing the name or path of the servlet
being called, as specified in the request URL, 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 the received trailer fields with all keys lower case or an empty Map if no trailers are presentObtain a Map of the trailer fields that is not backed by the request object. |
| 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 came in as a cookie; otherwise, falseChecks whether the requested session ID came in as a cookie. |
| public boolean | Returns: true if the session ID came in as part of a URL; otherwise, falseChecks whether the requested session ID came in as part of the request URL. |
| 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: true if trailers are ready to be readAre trailer fields ready to be read (there may still be no trailers to read). |
| 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 | |
| public void | |
| public default PushBuilder | Returns: A builder that can be used to generate push requests based on this request ornull if push is not
supported. Note that even if a PushBuilder instance is returned, by the time that
PushBuilder#push() is called, it may no longer be valid to push a request and the push
request will be ignored.Obtain a builder for generating push requests. |
| public < The type of the upgrade handler 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 Triggers the same authentication process as would be triggered if the request is for a resource that is protected by a security constraint.
| |
| changeSessionId | back to summary |
|---|---|
| public String changeSessionId() Changes the session ID of the session associated with this request. This method does not create a new session object it only changes the ID of the current session.
| |
| 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.
| |
| 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() Obtain the mapping information for this request.
| |
| 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 named Part or null if the Part does not exist. Triggers upload of all Parts.
| |
| getParts | back to summary |
|---|---|
| public Collection Return a collection of all uploaded Parts.
| |
| 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 The URL will be canonicalized as per section 3.5 of the specification before the path information, if any, is extracted.
| |
| 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 a 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.
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. The URL will be canonicalized as per section 3.5 of the specification before the path information, if any, is extracted. 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 Obtain a Map of the trailer fields that is not backed by the request object. | |
| getUserPrincipal | back to summary |
|---|---|
| public Principal getUserPrincipal() Returns a
| |
| isRequestedSessionIdFromCookie | back to summary |
|---|---|
| public boolean isRequestedSessionIdFromCookie() Checks whether the requested session ID came in as a cookie.
| |
| isRequestedSessionIdFromURL | back to summary |
|---|---|
| public boolean isRequestedSessionIdFromURL() Checks whether the requested session ID came in as part of the request URL.
| |
| isRequestedSessionIdValid | back to summary |
|---|---|
| public boolean isRequestedSessionIdValid() Checks whether the requested session ID is still valid.
| |
| isTrailerFieldsReady | back to summary |
|---|---|
| public default boolean isTrailerFieldsReady() Are trailer fields ready to be read (there may still be no trailers to read). This method always returns
| |
| 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
| |
| login | back to summary |
|---|---|
| public void login(String username, String password) throws ServletException Authenticate the provided user name and password and then associated the authenticated user with the request.
| |
| logout | back to summary |
|---|---|
| public void logout() throws ServletException Removes any authenticated user from the request.
| |
| newPushBuilder | back to summary |
|---|---|
| public default PushBuilder newPushBuilder() Obtain a builder for generating push requests.
| |
| upgrade | back to summary |
|---|---|
| public <T extends HttpUpgradeHandler> T upgrade(Class<T> httpUpgradeHandlerClass) throws IOException, ServletException Start the HTTP upgrade process and create and instance of the provided protocol handler class. The connection
will be passed this instance once the current request/response pair has completed processing. Calling this method
sets the response status to
| |