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 javax.servlet.http.HttpServletRequest.
javax.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 ir 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 the
IP address on which the request was received.Returns the Internet Protocol (IP) address of 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 host name of the Internet Protocol (IP) interface on which the request was received. |
| public int | Returns: an integer specifying the port numberReturns the Internet Protocol (IP) port number of 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 BufferedReader | Returns: aBufferedReader containing the body of the requestRetrieves the body of the request as character data using
a |
| public String | Returns: the real path, or null if the translation cannot be performed.the path for which the real path is to be returned. path)
Deprecated
As of Version 2.1 of the Java Servlet API,
use
ServletContext#getRealPath instead.
|
| public String | Returns: aString containing the
IP address of the client that sent the requestReturns the Internet Protocol (IP) address of the client or last proxy that sent the request. |
| public String | Returns: aString containing the fully
qualified name of the clientReturns the fully qualified name of the client or the last proxy that sent the request. |
| public int | Returns: an integer specifying the port numberReturns the Internet Protocol (IP) source port of the client or last proxy that sent the request. |
| 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 RequestDispatchera 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: 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 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 ir is greater than Integer.MAX_VALUE. For HTTP servlets, same as the value of the CGI variable CONTENT_LENGTH.
| |
| 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. For HTTP servlets, same as the value of the CGI variable CONTENT_LENGTH.
| |
| 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 of the interface on which the request was received.
| |
| 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 host name of the Internet Protocol (IP) interface on which the request was received.
| |
| getLocalPort | back to summary |
|---|---|
| public int getLocalPort() Returns the Internet Protocol (IP) port number of the interface on which the request was received.
| |
| 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. For HTTP servlets, the value
returned is the same as the value of the CGI variable
| |
| getReader | back to summary |
|---|---|
| public BufferedReader getReader() throws IOException Retrieves the body of the request as character data using
a
| |
| getRealPath | back to summary |
|---|---|
| public String getRealPath(String path)
Deprecated As of Version 2.1 of the Java Servlet API,
use | |
| getRemoteAddr | back to summary |
|---|---|
| public String getRemoteAddr() Returns the Internet Protocol (IP) address of the client
or last proxy that sent the request.
For HTTP servlets, same as the value of the
CGI variable
| |
| getRemoteHost | back to summary |
|---|---|
| public String getRemoteHost() Returns the fully qualified name of the client
or the last proxy that sent the request.
If the engine cannot or chooses not to resolve the hostname
(to improve performance), this method returns the dotted-string form of
the IP address. For HTTP servlets, same as the value of the CGI variable
| |
| getRemotePort | back to summary |
|---|---|
| public int getRemotePort() Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
| |
| 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 The difference between this method and
| |
| 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 is the value of the part before ":" in the
| |
| getServerPort | back to summary |
|---|---|
| public int getServerPort() Returns the port number to which the request was sent.
It is the value of the part after ":" in the
| |
| 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. Names beginning with | |
| 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.
| |