ServletRequest
object and passes it as an argument to the servlet's service
method.
A ServletRequest
object provides data including parameter name and values, attributes, and an input
stream. Interfaces that extend ServletRequest
can provide additional protocol-specific data (for
example, HTTP data is provided by jakarta.servlet.http.HttpServletRequest
.
jakarta.servlet.http.HttpServletRequest
Modifier and Type | Method and Description |
---|---|
public AsyncContext | Returns: the AsyncContext that was created or reinitialized by the most recent invocation ofstartAsync or
startAsync(ServletRequest, ServletResponse) on this requestGets the AsyncContext that was created or reinitialized by the most recent invocation of |
public Object | Returns: anObject containing the value of the attribute, or null if the attribute does not
exista name)String specifying the name of the attributeReturns the value of the named attribute as an |
public Enumeration | Returns: anEnumeration of strings containing the names of the request's attributesReturns an |
public String | Returns: aString containing the name of the character encoding, or null if the request does
not specify a character encodingReturns the name of the character encoding used in the body of this request. |
public int | Returns: an integer containing the length of the request body or -1 if the length is not known or is greater than Integer.MAX_VALUE.Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known or is greater than Integer.MAX_VALUE. |
public long | Returns: a long containing the length of the request body or -1L if the length is not knownReturns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known. |
public String | Returns: aString containing the name of the MIME type of the request, or null if the type is not knownReturns the MIME type of the body of the request, or |
public DispatcherType | Returns: the dispatcher type of this requestGets the dispatcher type of this request. |
public ServletInputStream | Returns: aServletInputStream object containing the body of the requestRetrieves the body of the request as binary data using a |
public String | Returns: aString containing an IP address.Returns the Internet Protocol (IP) address representing the interface on which the request was received. |
public Locale | Returns: the preferredLocale for the clientReturns the preferred |
public Enumeration | Returns: anEnumeration of preferred Locale objects for the clientReturns an |
public String | Returns: aString containing the host name of the IP on which the request was received.Returns the fully qualified name of the address returned by |
public int | Returns: an integer specifying a port numberReturns the Internet Protocol (IP) port number representing the interface on which the request was received. |
public String | Returns: aString representing the single value of the parametera name)String specifying the name of the parameterReturns the value of a request parameter as a |
public Map | Returns: an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.Returns a java.util.Map of the parameters of this request. |
public Enumeration | Returns: anEnumeration of String objects, each String containing the name of a
request parameter; or an empty Enumeration if the request has no parametersReturns an |
public String[] | Returns: an array ofString objects containing the parameter's valuesa name)String containing the name of the parameter whose value is requestedReturns an array of |
public String | Returns: aString containing the protocol name and version numberReturns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1. |
public String | Returns: The request identifier if one is defined, otherwise an empty stringObtain the request identifier for this request as defined by the protocol in use. |
public BufferedReader | Returns: aBufferedReader containing the body of the requestRetrieves the body of the request as character data using a |
public String | Returns: aString containing an IP addressReturns the Internet Protocol (IP) of the remote end of the connection on which the request was received. |
public String | Returns: aString containing a fully qualified name or IP address.Returns the fully qualified name of the address returned by |
public int | Returns: an integer specifying the port numberReturns the Internet Protocol (IP) source port the remote end of the connection on which the request was received. |
public RequestDispatcher | Returns: aRequestDispatcher object that acts as a wrapper for the resource at the specified path, or
null if the servlet container cannot return a RequestDispatcher a path)String specifying the pathname to the resource. If it is relative, it must be relative
against the current servlet.Returns a |
public String | Returns: A unique identifier for the requestObtain a unique (within the lifetime of the Servlet container) identifier string for this request. |
public String | Returns: aString containing the name of the scheme used to make this requestReturns the name of the scheme used to make this request, for example, |
public String | Returns: aString containing the name of the serverReturns the host name of the server to which the request was sent. |
public int | Returns: an integer specifying the port numberReturns the port number to which the request was sent. |
public ServletConnection | Returns: The network connection details.Obtain details of the network connection to the Servlet container that is being used by this request. |
public ServletContext | Returns: the servlet context to which this ServletRequest was last dispatchedGets the servlet context to which this ServletRequest was last dispatched. |
public boolean | Returns: true if this request has been put into asynchronous mode, false otherwiseChecks if this request has been put into asynchronous mode. |
public boolean | Returns: true if this request supports asynchronous operation, false otherwiseChecks if this request supports asynchronous operation. |
public boolean | Returns: a boolean indicating if the request was made using a secure channelReturns a boolean indicating whether this request was made using a secure channel, such as HTTPS. |
public void | removeAttribute(String
a name)String specifying the name of the attribute to removeRemoves an attribute from this request. |
public void | setAttribute(String
a name, Object String specifying the name of the attributethe o)Object to be storedStores an attribute in this request. |
public void | setCharacterEncoding(String
String containing the name of the character encoding.Overrides the name of the character encoding used in the body of this request. |
public AsyncContext | Returns: the (re)initialized AsyncContextPuts this request into asynchronous mode, and initializes its |
public AsyncContext | Returns: the (re)initialized AsyncContextthe ServletRequest used to initialize the AsyncContext servletRequest, ServletResponse the ServletResponse used to initialize the AsyncContext servletResponse)Puts this request into asynchronous mode, and initializes its |
getAsyncContext | back to summary |
---|---|
public AsyncContext getAsyncContext() Gets the AsyncContext that was created or reinitialized by the most recent invocation of
|
getAttribute | back to summary |
---|---|
public Object getAttribute(String name) Returns the value of the named attribute as an
Attributes can be set two ways. The servlet container may set attributes to make available custom information about a
request. For example, for requests made using HTTPS, the attribute
Attribute names should follow the same conventions as package names. This specification reserves names matching
|
getAttributeNames | back to summary |
---|---|
public Enumeration Returns an
|
getCharacterEncoding | back to summary |
---|---|
public String getCharacterEncoding() Returns the name of the character encoding used in the body of this request. This method returns
|
getContentLength | back to summary |
---|---|
public int getContentLength() Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known or is greater than Integer.MAX_VALUE.
|
getContentLengthLong | back to summary |
---|---|
public long getContentLengthLong() Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.
|
getContentType | back to summary |
---|---|
public String getContentType() Returns the MIME type of the body of the request, or
|
getDispatcherType | back to summary |
---|---|
public DispatcherType getDispatcherType() Gets the dispatcher type of this request. The dispatcher type of a request is used by the container to select the filters that need to be applied to the request: Only filters with matching dispatcher type and url patterns will be applied. Allowing a filter that has been configured for multiple dispatcher types to query a request for its dispatcher type allows the filter to process the request differently depending on its dispatcher type.
The initial dispatcher type of a request is defined as
|
getInputStream | back to summary |
---|---|
public ServletInputStream getInputStream() throws IOException Retrieves the body of the request as binary data using a
|
getLocalAddr | back to summary |
---|---|
public String getLocalAddr() Returns the Internet Protocol (IP) address representing the interface on which the request was received. In some cases a protocol specific mechanism, such as RFC 7239, may be used to obtain an address different to that of the actual TCP/IP connection.
|
getLocale | back to summary |
---|---|
public Locale getLocale() Returns the preferred
|
getLocales | back to summary |
---|---|
public Enumeration Returns an
|
getLocalName | back to summary |
---|---|
public String getLocalName() Returns the fully qualified name of the address returned by
|
getLocalPort | back to summary |
---|---|
public int getLocalPort() Returns the Internet Protocol (IP) port number representing the interface on which the request was received. In some cases, a protocol specific mechanism such as RFC 7239 may be used to obtain an address different to that of the actual TCP/IP connection.
|
getParameter | back to summary |
---|---|
public String getParameter(String name) Returns the value of a request parameter as a
You should only use this method when you are sure the parameter has only one value. If the parameter might have more
than one value, use
If you use this method with a multivalued parameter, the value returned is equal to the first value in the array
returned by
If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body
directly via
|
getParameterMap | back to summary |
---|---|
public Map Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data. |
getParameterNames | back to summary |
---|---|
public Enumeration Returns an
|
getParameterValues | back to summary |
---|---|
public String[] getParameterValues(String name) Returns an array of If the parameter has a single value, the array has a length of 1.
|
getProtocol | back to summary |
---|---|
public String getProtocol() Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
|
getProtocolRequestId | back to summary |
---|---|
public String getProtocolRequestId() Obtain the request identifier for this request as defined by the protocol in use. Note that some protocols do not define such an identifier. Examples of protocol provided request identifiers include:
|
getReader | back to summary |
---|---|
public BufferedReader getReader() throws IOException Retrieves the body of the request as character data using a
|
getRemoteAddr | back to summary |
---|---|
public String getRemoteAddr() Returns the Internet Protocol (IP) of the remote end of the connection on which the request was received. By default this is either the address of the client or last proxy that sent the request. In some cases a protocol specific mechanism, such as RFC 7239, may be used to obtain an address different to that of the actual TCP/IP connection.
|
getRemoteHost | back to summary |
---|---|
public String getRemoteHost() Returns the fully qualified name of the address returned by
|
getRemotePort | back to summary |
---|---|
public int getRemotePort() Returns the Internet Protocol (IP) source port the remote end of the connection on which the request was received. By default this is either the port of the client or last proxy that sent the request. In some cases, protocol specific mechanisms such as RFC 7239 may be used to obtain a port different to that of the actual TCP/IP connection.
|
getRequestDispatcher | back to summary |
---|---|
public RequestDispatcher getRequestDispatcher(String path) Returns a
The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path
begins with a "/" it is interpreted as relative to the current context root. This method returns Using a RequestDispatcher, requests may be dispatched to any part of the web application bypassing both implicit (no direct access to WEB-INF or META-INF) and explicit (defined by the web application) security constraints. Unsanitized user provided data must not be used to construct the path passed to the RequestDispatcher as it is very likely to create a security vulnerability in the application.
The difference between this method and
|
getRequestId | back to summary |
---|---|
public String getRequestId() Obtain a unique (within the lifetime of the Servlet container) identifier string for this request. There is no defined format for this string. The format is implementation dependent.
|
getScheme | back to summary |
---|---|
public String getScheme() Returns the name of the scheme used to make this request, for example,
|
getServerName | back to summary |
---|---|
public String getServerName() Returns the host name of the server to which the request was sent. It may be derived from a protocol specific
mechanism, such as the
|
getServerPort | back to summary |
---|---|
public int getServerPort() Returns the port number to which the request was sent. It may be derived from a protocol specific mechanism, such as
the
|
getServletConnection | back to summary |
---|---|
public ServletConnection getServletConnection() Obtain details of the network connection to the Servlet container that is being used by this request. The information presented may differ from information presented elsewhere in the Servlet API as raw information is presented without adjustments for, example, use of reverse proxies that may be applied elsewhere in the Servlet API.
|
getServletContext | back to summary |
---|---|
public ServletContext getServletContext() Gets the servlet context to which this ServletRequest was last dispatched.
|
isAsyncStarted | back to summary |
---|---|
public boolean isAsyncStarted() Checks if this request has been put into asynchronous mode.
A ServletRequest is put into asynchronous mode by calling
This method returns false if this request was put into asynchronous mode, but has since been dispatched
using one of the
|
isAsyncSupported | back to summary |
---|---|
public boolean isAsyncSupported() Checks if this request supports asynchronous operation. Asynchronous operation is disabled for this request if this request is within the scope of a filter or servlet that has not been annotated or flagged in the deployment descriptor as being able to support asynchronous handling.
|
isSecure | back to summary |
---|---|
public boolean isSecure() Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
|
removeAttribute | back to summary |
---|---|
public void removeAttribute(String name) Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the request is being handled.
Attribute names should follow the same conventions as package names. Names beginning with
|
setAttribute | back to summary |
---|---|
public void setAttribute(String name, Object o) Stores an attribute in this request. Attributes are reset between requests. This method is most often used in
conjunction with
Attribute names should follow the same conventions as package names. |
setCharacterEncoding | back to summary |
---|---|
public void setCharacterEncoding(String env) throws UnsupportedEncodingException Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader(). Otherwise, it has no effect.
|
startAsync | back to summary |
---|---|
public AsyncContext startAsync() throws IllegalStateException Puts this request into asynchronous mode, and initializes its
Calling this method will cause committal of the associated response to be delayed until
Calling
This method clears the list of Subsequent invocations of this method, or its overloaded variant, will return the same AsyncContext instance, reinitialized as appropriate.
|
startAsync | back to summary |
---|---|
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException Puts this request into asynchronous mode, and initializes its
The ServletRequest and ServletResponse arguments must be the same instances, or instances of
Calling this method will cause committal of the associated response to be delayed until
Calling
This method clears the list of Subsequent invocations of this method, or its zero-argument variant, will return the same AsyncContext instance, reinitialized as appropriate. If a call to this method is followed by a call to its zero-argument variant, the specified (and possibly wrapped) request and response objects will remain locked in on the returned AsyncContext.
|