public class Request extends java.lang.Object implements HttpServletRequest
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Boolean |
asyncSupported |
protected java.lang.String |
authType
Authentication type.
|
protected static int |
CACHED_POST_LEN
Post data buffer.
|
protected Connector |
connector
Associated Catalina connector.
|
protected Cookie[] |
cookies
The set of cookies associated with this Request.
|
protected boolean |
cookiesConverted
Cookie parsed flag.
|
protected boolean |
cookiesParsed
Cookie headers parsed flag.
|
protected Request |
coyoteRequest
Coyote request.
|
protected static java.util.Locale |
defaultLocale
The default Locale if none are specified.
|
protected RequestFacade |
facade
The facade associated with this request.
|
protected FilterChain |
filterChain
Filter chain associated with the request.
|
protected java.text.SimpleDateFormat[] |
formats
Deprecated.
Unused. This will be removed in Tomcat 10
|
protected static java.util.TimeZone |
GMT_ZONE
Deprecated.
Unused. This will be removed in Tomcat 10.
|
protected InputBuffer |
inputBuffer
The associated input buffer.
|
protected CoyoteInputStream |
inputStream
ServletInputStream.
|
protected DispatcherType |
internalDispatcherType
The current dispatcher type.
|
protected java.lang.String |
localAddr
Local address
|
protected java.util.ArrayList<java.util.Locale> |
locales
The preferred Locales associated with this Request.
|
protected boolean |
localesParsed
Parse locales.
|
protected java.lang.String |
localName
Local address
|
protected int |
localPort
Local port
|
protected MappingData |
mappingData
Mapping data.
|
protected ParameterMap<java.lang.String,java.lang.String[]> |
parameterMap
Hash map used in the getParametersMap method.
|
protected boolean |
parametersParsed
Request parameters parsed flag.
|
protected java.util.Collection<Part> |
parts
The parts, if any, uploaded with this request.
|
protected java.lang.Exception |
partsParseException
The exception thrown, if any when parsing the parts.
|
protected java.lang.String |
peerAddr
Connection peer address.
|
protected byte[] |
postData |
protected CoyoteReader |
reader
Reader.
|
protected java.lang.String |
remoteAddr
Remote address.
|
protected java.lang.String |
remoteHost
Remote host.
|
protected int |
remotePort
Remote port
|
protected java.lang.Object |
requestDispatcherPath
The current request dispatcher path.
|
protected boolean |
requestedSessionCookie
Was the requested session ID received in a cookie?
|
protected java.lang.String |
requestedSessionId
The requested session ID (if any) for this request.
|
protected boolean |
requestedSessionSSL
Was the requested session ID obtained from the SSL session?
|
protected boolean |
requestedSessionURL
Was the requested session ID received in a URL?
|
protected Response |
response
The response with which this request is associated.
|
protected boolean |
secure
Secure flag.
|
protected Session |
session
The currently active session for this request.
|
protected static StringManager |
sm
The string manager for this package.
|
protected boolean |
sslAttributesParsed
Flag that indicates if SSL attributes have been parsed to improve performance for applications (usually
frameworks) that make multiple calls to
getAttributeNames(). |
protected javax.security.auth.Subject |
subject
The Subject associated with the current AccessControlContext
|
protected B2CConverter |
URIConverter
URI byte to char converter.
|
protected java.security.Principal |
userPrincipal
User principal.
|
protected boolean |
usingInputStream
Using stream flag.
|
protected boolean |
usingReader
Using reader flag.
|
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH| Constructor and Description |
|---|
Request(Connector connector)
Create a new Request object associated with the given Connector.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(Cookie cookie)
Add a Cookie to the set of Cookies associated with this Request.
|
void |
addLocale(java.util.Locale locale)
Add a Locale to the set of preferred Locales for this Request.
|
protected void |
addPathParameter(java.lang.String name,
java.lang.String value) |
boolean |
authenticate(HttpServletResponse response)
Triggers the same authentication process as would be triggered if the request is for a resource that is protected
by a security constraint.
|
java.lang.String |
changeSessionId()
Changes the session ID of the session associated with this request.
|
void |
changeSessionId(java.lang.String newSessionId)
Change the ID of the session that this request is associated with.
|
protected void |
checkSwallowInput()
Check the configuration for aborted uploads and if configured to do so, disable the swallowing of any remaining
input and close the connection once the response has been written.
|
void |
clearCookies()
Clear the collection of Cookies associated with this Request.
|
void |
clearLocales()
Clear the collection of Locales associated with this Request.
|
protected void |
convertCookies()
Converts the parsed cookies (parsing the Cookie headers first if they have not been parsed) into Cookie objects.
|
ServletInputStream |
createInputStream()
Create and return a ServletInputStream to read the content associated with this Request.
|
protected Session |
doGetSession(boolean create) |
void |
finishRequest()
Perform whatever actions are required to flush and close the input stream or reader, in a single operation.
|
AsyncContext |
getAsyncContext()
Get the current AsyncContext.
|
AsyncContextImpl |
getAsyncContextInternal() |
java.lang.Object |
getAttribute(java.lang.String name)
Returns the value of the named attribute as an
Object, or null if no attribute of the
given name exists. |
java.util.Enumeration<java.lang.String> |
getAttributeNames()
Return the names of all request attributes for this Request, or an empty
Enumeration if there are
none. |
java.lang.String |
getAuthType()
Return the authentication type used for this Request.
|
java.lang.String |
getCharacterEncoding()
Returns the name of the character encoding used in the body of this request.
|
Connector |
getConnector() |
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.
|
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.
|
java.lang.String |
getContentType()
Returns the MIME type of the body of the request, or
null if the type is not known. |
Context |
getContext()
Return the Context within which this Request is being processed.
|
java.lang.String |
getContextPath()
Return the portion of the request URI used to select the Context of the Request.
|
Cookie[] |
getCookies()
Return the set of Cookies received with this Request.
|
Request |
getCoyoteRequest()
Get the Coyote request.
|
long |
getDateHeader(java.lang.String name)
Return the value of the specified date header, if any; otherwise return -1.
|
java.lang.String |
getDecodedRequestURI()
Get the decoded request URI.
|
MessageBytes |
getDecodedRequestURIMB()
Get the decoded request URI.
|
boolean |
getDiscardFacades()
Get the recycling strategy of the facade objects.
|
DispatcherType |
getDispatcherType() |
FilterChain |
getFilterChain()
Get filter chain associated with the request.
|
java.lang.String |
getHeader(java.lang.String name)
Return the first value of the specified header, if any; otherwise, return
null |
java.util.Enumeration<java.lang.String> |
getHeaderNames()
Returns an enumeration of all the header names this request contains.
|
java.util.Enumeration<java.lang.String> |
getHeaders(java.lang.String name)
Return all of the values of the specified header, if any; otherwise, return an empty enumeration.
|
Host |
getHost() |
HttpServletMapping |
getHttpServletMapping()
Obtain the mapping information for this request.
|
ServletInputStream |
getInputStream()
Retrieves the body of the request as binary data using a
ServletInputStream. |
int |
getIntHeader(java.lang.String name)
Return the value of the specified header as an integer, or -1 if there is no such header for this request.
|
java.lang.String |
getLocalAddr()
Returns the Internet Protocol (IP) address of the interface on which the request was received.
|
java.util.Locale |
getLocale()
Returns the preferred
Locale that the client will accept content in, based on the Accept-Language
header. |
java.util.Enumeration<java.util.Locale> |
getLocales()
Returns an
Enumeration of Locale objects indicating, in decreasing order starting with
the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. |
java.lang.String |
getLocalName()
Returns the host name of the Internet Protocol (IP) interface on which the request was received.
|
int |
getLocalPort()
Returns the Internet Protocol (IP) port number of the interface on which the request was received.
|
MappingData |
getMappingData() |
java.lang.String |
getMethod()
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
|
java.lang.Object |
getNote(java.lang.String name) |
java.lang.String |
getParameter(java.lang.String name)
Returns the value of a request parameter as a
String, or null if the parameter does not
exist. |
java.util.Map<java.lang.String,java.lang.String[]> |
getParameterMap()
Returns a
Map of the parameters of this request. |
java.util.Enumeration<java.lang.String> |
getParameterNames()
Returns an
Enumeration of String objects containing the names of the parameters
contained in this request. |
java.lang.String[] |
getParameterValues(java.lang.String name)
Returns an array of
String objects containing all of the values the given request parameter has, or
null if the parameter does not exist. |
Part |
getPart(java.lang.String name)
Gets the named Part or null if the Part does not exist.
|
java.util.Collection<Part> |
getParts()
Return a collection of all uploaded Parts.
|
java.lang.String |
getPathInfo()
Returns any extra path information associated with the URL the client sent when it made this request.
|
protected java.lang.String |
getPathParameter(java.lang.String name) |
java.lang.String |
getPathTranslated()
Returns any extra path information after the servlet name but before the query string, and translates it to a
real path.
|
java.lang.String |
getPeerAddr() |
java.security.Principal |
getPrincipal() |
java.lang.String |
getProtocol()
Returns the name and version of the protocol the request uses in the form
protocol/majorVersion.minorVersion, for example, HTTP/1.1.
|
java.lang.String |
getQueryString()
Returns the query string that is contained in the request URL after the path.
|
java.io.BufferedReader |
getReader()
Read the Reader wrapping the input stream for this Request.
|
java.lang.String |
getRealPath(java.lang.String path)
Deprecated.
As of version 2.1 of the Java Servlet API, use
ServletContext.getRealPath(). |
java.lang.String |
getRemoteAddr()
Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
|
java.lang.String |
getRemoteHost()
Returns the fully qualified name of the client or the last proxy that sent the request.
|
int |
getRemotePort()
Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
|
java.lang.String |
getRemoteUser()
Returns the login of the user making this request, if the user has been authenticated, or
null if
the user has not been authenticated. |
HttpServletRequest |
getRequest() |
RequestDispatcher |
getRequestDispatcher(java.lang.String path)
Returns a
RequestDispatcher object that acts as a wrapper for the resource located at the given path. |
java.lang.String |
getRequestedSessionId()
Returns the session ID specified by the client.
|
MessageBytes |
getRequestPathMB()
Get the request path.
|
java.lang.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.
|
java.lang.StringBuffer |
getRequestURL()
Reconstructs the URL the client used to make the request.
|
Response |
getResponse() |
java.lang.String |
getScheme()
Returns the name of the scheme used to make this request, for example,
http, https, or
ftp. |
ServerCookies |
getServerCookies()
Return the server representation of the cookies associated with this request.
|
java.lang.String |
getServerName()
Returns the host name of the server to which the request was sent.
|
int |
getServerPort()
Returns the port number to which the request was sent.
|
ServletContext |
getServletContext() |
java.lang.String |
getServletPath()
Returns the part of this request's URL that calls the servlet.
|
HttpSession |
getSession()
Returns the current session associated with this request, or if the request does not have a session, creates one.
|
HttpSession |
getSession(boolean create)
Returns the current
HttpSession associated with this request or, if there is no current session and
create is true, returns a new session. |
Session |
getSessionInternal() |
Session |
getSessionInternal(boolean create) |
java.io.InputStream |
getStream() |
java.util.Map<java.lang.String,java.lang.String> |
getTrailerFields()
Obtain a Map of the trailer fields that is not backed by the request object.
|
protected B2CConverter |
getURIConverter() |
java.security.Principal |
getUserPrincipal()
Returns a
java.security.Principal object containing the name of the current authenticated user. |
Wrapper |
getWrapper() |
boolean |
isAsync() |
boolean |
isAsyncCompleting() |
boolean |
isAsyncDispatching() |
boolean |
isAsyncStarted() |
boolean |
isAsyncSupported() |
boolean |
isFinished() |
boolean |
isParametersParsed() |
boolean |
isRequestedSessionIdFromCookie()
Checks whether the requested session ID came in as a cookie.
|
boolean |
isRequestedSessionIdFromUrl()
Deprecated.
As of Version 2.1 of the Java Servlet API, use
isRequestedSessionIdFromURL() instead. |
boolean |
isRequestedSessionIdFromURL()
Checks whether the requested session ID came in as part of the request URL.
|
boolean |
isRequestedSessionIdValid()
Checks whether the requested session ID is still valid.
|
boolean |
isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
|
boolean |
isTrailerFieldsReady()
Are trailer fields ready to be read (there may still be no trailers to read).
|
boolean |
isUserInRole(java.lang.String role)
Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
|
void |
login(java.lang.String username,
java.lang.String password)
Authenticate the provided user name and password and then associated the authenticated user with the request.
|
void |
logout()
Removes any authenticated user from the request.
|
PushBuilder |
newPushBuilder()
Obtain a builder for generating push requests.
|
PushBuilder |
newPushBuilder(HttpServletRequest request) |
protected void |
parseCookies()
Parse cookies.
|
protected void |
parseLocales()
Parse request locales.
|
protected void |
parseLocalesHeader(java.lang.String value,
java.util.TreeMap<java.lang.Double,java.util.ArrayList<java.util.Locale>> locales)
Parse accept-language header value.
|
protected void |
parseParameters()
Parse request parameters.
|
protected byte[] |
readChunkedPostBody()
Read chunked post body.
|
protected int |
readPostBody(byte[] body,
int len)
Deprecated.
Unused. Will be removed in Tomcat 11.0.x onwards. Use
readPostBodyFully(byte[], int) |
protected void |
readPostBodyFully(byte[] body,
int len)
Read post body into an array.
|
void |
recycle()
Release all object references, and initialize instance variables, in preparation for reuse of this object.
|
protected void |
recycleCookieInfo(boolean recycleCoyote) |
protected void |
recycleSessionInfo() |
void |
removeAttribute(java.lang.String name)
Remove the specified request attribute if it exists.
|
void |
removeNote(java.lang.String name)
Remove any object bound to the specified name in the internal notes for this request.
|
void |
setAsyncSupported(boolean asyncSupported) |
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Set the specified request attribute to the specified value.
|
void |
setAuthType(java.lang.String type)
Set the authentication type used for this request, if any; otherwise set the type to
null. |
void |
setCharacterEncoding(java.lang.String enc)
Overrides the name of the character encoding used in the body of this request.
|
void |
setContentType(java.lang.String contentType)
Set the content type for this Request.
|
void |
setCoyoteRequest(Request coyoteRequest)
Set the Coyote request.
|
void |
setFilterChain(FilterChain filterChain)
Set filter chain associated with the request.
|
void |
setLocalPort(int port)
Set the port number of the server to process this request.
|
void |
setNote(java.lang.String name,
java.lang.Object value)
Bind an object to a specified name in the internal notes associated with this request, replacing any existing
binding for this name.
|
void |
setPathInfo(java.lang.String path)
Set the path information for this Request.
|
void |
setRemoteAddr(java.lang.String remoteAddr)
Set the IP address of the remote client associated with this Request.
|
void |
setRemoteHost(java.lang.String remoteHost)
Set the fully qualified name of the remote client associated with this Request.
|
void |
setRequest(HttpServletRequest applicationRequest)
Set a wrapped HttpServletRequest to pass to the application.
|
void |
setRequestedSessionCookie(boolean flag)
Set a flag indicating whether or not the requested session ID for this request came in through a cookie.
|
void |
setRequestedSessionId(java.lang.String id)
Set the requested session ID for this request.
|
void |
setRequestedSessionSSL(boolean flag)
Set a flag indicating whether or not the requested session ID for this request came in through SSL.
|
void |
setRequestedSessionURL(boolean flag)
Set a flag indicating whether or not the requested session ID for this request came in through a URL.
|
void |
setResponse(Response response)
Set the Response with which this Request is associated.
|
void |
setSecure(boolean secure)
Set the value to be returned by
isSecure() for this Request. |
void |
setServerPort(int port)
Set the port number of the server to process this request.
|
protected void |
setURIConverter(B2CConverter URIConverter)
Set the URI converter.
|
void |
setUserPrincipal(java.security.Principal principal)
Set the Principal who has been authenticated for this Request.
|
AsyncContext |
startAsync() |
AsyncContext |
startAsync(ServletRequest request,
ServletResponse response) |
protected java.lang.String |
unescape(java.lang.String s) |
<T extends HttpUpgradeHandler> |
upgrade(java.lang.Class<T> httpUpgradeHandlerClass)
Start the HTTP upgrade process and create and instance of the provided protocol handler class.
|
protected Request coyoteRequest
@Deprecated protected static final java.util.TimeZone GMT_ZONE
protected static final StringManager sm
protected Cookie[] cookies
@Deprecated protected final java.text.SimpleDateFormat[] formats
protected static final java.util.Locale defaultLocale
protected boolean sslAttributesParsed
getAttributeNames().protected final java.util.ArrayList<java.util.Locale> locales
protected java.lang.String authType
protected DispatcherType internalDispatcherType
protected final InputBuffer inputBuffer
protected CoyoteInputStream inputStream
protected CoyoteReader reader
protected boolean usingInputStream
protected boolean usingReader
protected java.security.Principal userPrincipal
protected boolean parametersParsed
protected boolean cookiesParsed
protected boolean cookiesConverted
protected boolean secure
protected transient javax.security.auth.Subject subject
protected static final int CACHED_POST_LEN
protected byte[] postData
protected ParameterMap<java.lang.String,java.lang.String[]> parameterMap
protected java.util.Collection<Part> parts
protected java.lang.Exception partsParseException
protected Session session
protected java.lang.Object requestDispatcherPath
protected boolean requestedSessionCookie
protected java.lang.String requestedSessionId
protected boolean requestedSessionURL
protected boolean requestedSessionSSL
protected boolean localesParsed
protected int localPort
protected java.lang.String remoteAddr
protected java.lang.String peerAddr
protected java.lang.String remoteHost
protected int remotePort
protected java.lang.String localAddr
protected java.lang.String localName
protected java.lang.Boolean asyncSupported
protected final Connector connector
protected FilterChain filterChain
protected final MappingData mappingData
protected RequestFacade facade
protected Response response
protected B2CConverter URIConverter
public Request(Connector connector)
connector - The Connector with which this Request object will always be associated. In normal usage this
must be non-null. In some test scenarios, it may be possible to use a null Connector without
triggering an NPE.public void setCoyoteRequest(Request coyoteRequest)
coyoteRequest - The Coyote requestpublic Request getCoyoteRequest()
protected void addPathParameter(java.lang.String name,
java.lang.String value)
protected java.lang.String getPathParameter(java.lang.String name)
public void setAsyncSupported(boolean asyncSupported)
public void recycle()
protected void recycleSessionInfo()
protected void recycleCookieInfo(boolean recycleCoyote)
public Connector getConnector()
public Context getContext()
This is available as soon as the appropriate Context is identified. Note that availability of a Context allows
getContextPath() to return a value, and thus enables parsing of the request URI.
public boolean getDiscardFacades()
true if no connector is associated with
this requestpublic FilterChain getFilterChain()
public void setFilterChain(FilterChain filterChain)
filterChain - new filter chainpublic Host getHost()
public MappingData getMappingData()
public HttpServletRequest getRequest()
ServletRequest for which this object is the facade. This method must be implemented by a
subclass.public void setRequest(HttpServletRequest applicationRequest)
getRequest(), wrap it and then call this method with the wrapped request.applicationRequest - The wrapped request to pass to the applicationpublic Response getResponse()
public void setResponse(Response response)
response - The new associated responsepublic java.io.InputStream getStream()
protected B2CConverter getURIConverter()
protected void setURIConverter(B2CConverter URIConverter)
URIConverter - the new URI converterpublic Wrapper getWrapper()
public ServletInputStream createInputStream() throws java.io.IOException
java.io.IOException - if an input/output error occurspublic void finishRequest()
throws java.io.IOException
java.io.IOException - if an input/output error occurspublic java.lang.Object getNote(java.lang.String name)
name - Name of the note to be returnednull if
no such binding exists.public void removeNote(java.lang.String name)
name - Name of the note to be removedpublic void setLocalPort(int port)
port - The server portpublic void setNote(java.lang.String name,
java.lang.Object value)
name - Name to which the object should be boundvalue - Object to be bound to the specified namepublic void setRemoteAddr(java.lang.String remoteAddr)
remoteAddr - The remote IP addresspublic void setRemoteHost(java.lang.String remoteHost)
remoteHost - The remote host namepublic void setSecure(boolean secure)
isSecure() for this Request.secure - The new isSecure valuepublic void setServerPort(int port)
port - The server portpublic java.lang.Object getAttribute(java.lang.String name)
javax.servlet.ServletRequestObject, or null if no attribute of the
given name exists.
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
javax.servlet.request.X509Certificate can be used to retrieve information on the certificate of the
client. Attributes can also be set programmatically using ServletRequest.setAttribute(java.lang.String, java.lang.Object). This allows
information to be embedded into a request before a RequestDispatcher call.
Attribute names should follow the same conventions as package names. Names beginning with java.* and
javax.* are reserved for use by the Servlet specification. Names beginning with sun.*,
com.sun.*, oracle.* and com.oracle.*) are reserved for use by Oracle
Corporation.
getAttribute in interface ServletRequestname - Name of the request attribute to returnnull.public long getContentLengthLong()
javax.servlet.ServletRequestgetContentLengthLong in interface ServletRequestpublic java.util.Enumeration<java.lang.String> getAttributeNames()
Enumeration if there are
none. Note that the attribute names returned will only be those for the attributes set via
setAttribute(String, Object). Tomcat internal attributes will not be included although they are
accessible via getAttribute(String). The Tomcat internal attributes include:
Globals.DISPATCHER_TYPE_ATTRGlobals.DISPATCHER_REQUEST_PATH_ATTRGlobals.ASYNC_SUPPORTED_ATTRGlobals.CERTIFICATES_ATTR (SSL connections only)Globals.CIPHER_SUITE_ATTR (SSL connections only)Globals.KEY_SIZE_ATTR (SSL connections only)Globals.SSL_SESSION_ID_ATTR (SSL connections only)Globals.SSL_SESSION_MGR_ATTR (SSL connections only)Globals.PARAMETER_PARSE_FAILED_ATTRgetAttributeNames in interface ServletRequestpublic java.lang.String getCharacterEncoding()
javax.servlet.ServletRequestnull if the no character encoding has been specified. The following priority order is used to
determine the specified encoding:
ServletContext.setRequestCharacterEncoding(String)getCharacterEncoding in interface ServletRequestpublic int getContentLength()
javax.servlet.ServletRequestgetContentLength in interface ServletRequestpublic java.lang.String getContentType()
javax.servlet.ServletRequestnull if the type is not known. For HTTP
servlets, same as the value of the CGI variable CONTENT_TYPE.getContentType in interface ServletRequestpublic void setContentType(java.lang.String contentType)
contentType - The content typepublic ServletInputStream getInputStream() throws java.io.IOException
javax.servlet.ServletRequestServletInputStream. Either this method or
ServletRequest.getReader() may be called to read the body, not both.getInputStream in interface ServletRequestcreateInputStream().java.lang.IllegalStateException - if getReader() has already been called for this requestjava.io.IOException - if an input/output error occurspublic java.util.Locale getLocale()
javax.servlet.ServletRequestLocale that the client will accept content in, based on the Accept-Language
header. If the client request doesn't provide an Accept-Language header, this method returns the default locale
for the server.getLocale in interface ServletRequestAccept-Language header that was encountered. If the request did not specify a preferred
language, the server's default Locale is returned.public java.util.Enumeration<java.util.Locale> getLocales()
javax.servlet.ServletRequestEnumeration of Locale objects indicating, in decreasing order starting with
the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the
client request doesn't provide an Accept-Language header, this method returns an Enumeration
containing one Locale, the default locale for the server.getLocales in interface ServletRequestAccept-Language headers that were encountered. If the request did not specify a
preferred language, the server's default Locale is returned.public java.lang.String getParameter(java.lang.String name)
javax.servlet.ServletRequestString, or null if the parameter does not
exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are
contained in the query string or posted form data.
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 ServletRequest.getParameterValues(java.lang.String).
If you use this method with a multivalued parameter, the value returned is equal to the first value in the array
returned by getParameterValues.
If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the
body directly via ServletRequest.getInputStream() or ServletRequest.getReader() can interfere with the execution of this method.
getParameter in interface ServletRequestname - Name of the desired request parameternull. If there is
more than one value defined, return only the first one.ServletRequest.getParameterValues(java.lang.String)public java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()
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.getParameterMap in interface ServletRequestMap containing parameter names as keys and parameter values as map values.public java.util.Enumeration<java.lang.String> getParameterNames()
javax.servlet.ServletRequestEnumeration of String objects containing the names of the parameters
contained in this request. If the request has no parameters, the method returns an empty
Enumeration.getParameterNames in interface ServletRequestpublic java.lang.String[] getParameterValues(java.lang.String name)
javax.servlet.ServletRequestString objects containing all of the values the given request parameter has, or
null if the parameter does not exist.
If the parameter has a single value, the array has a length of 1.
getParameterValues in interface ServletRequestname - Name of the desired request parameternull.ServletRequest.getParameter(java.lang.String)public java.lang.String getProtocol()
javax.servlet.ServletRequestSERVER_PROTOCOL.getProtocol in interface ServletRequestpublic java.io.BufferedReader getReader()
throws java.io.IOException
BufferedReader around the servlet input stream returned by createInputStream().getReader in interface ServletRequestjava.lang.IllegalStateException - if getInputStream() has already been called for this requestjava.io.IOException - if an input/output error occursServletRequest.getInputStream()@Deprecated public java.lang.String getRealPath(java.lang.String path)
ServletContext.getRealPath().getRealPath in interface ServletRequestpath - Path to be translatedpublic java.lang.String getRemoteAddr()
javax.servlet.ServletRequestREMOTE_ADDR.getRemoteAddr in interface ServletRequestpublic java.lang.String getPeerAddr()
public java.lang.String getRemoteHost()
javax.servlet.ServletRequestREMOTE_HOST.getRemoteHost in interface ServletRequestpublic int getRemotePort()
javax.servlet.ServletRequestgetRemotePort in interface ServletRequestpublic java.lang.String getLocalName()
javax.servlet.ServletRequestgetLocalName in interface ServletRequestpublic java.lang.String getLocalAddr()
javax.servlet.ServletRequestgetLocalAddr in interface ServletRequestpublic int getLocalPort()
javax.servlet.ServletRequestgetLocalPort in interface ServletRequestpublic RequestDispatcher getRequestDispatcher(java.lang.String path)
javax.servlet.ServletRequestRequestDispatcher object that acts as a wrapper for the resource located at the given path. A
RequestDispatcher object can be used to forward a request to the resource or to include the resource
in a response. The resource can be dynamic or static.
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
null if the servlet container cannot return a RequestDispatcher.
The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a
relative path.
getRequestDispatcher in interface ServletRequestpath - Path of the resource to be wrappedRequestDispatcher,
ServletContext.getRequestDispatcher(java.lang.String)public java.lang.String getScheme()
javax.servlet.ServletRequesthttp, https, or
ftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.getScheme in interface ServletRequestpublic java.lang.String getServerName()
javax.servlet.ServletRequestHost header value, if any, or the resolved server name, or the server IP address.getServerName in interface ServletRequestpublic int getServerPort()
javax.servlet.ServletRequestHost header value, if any, or the server port where the client connection was accepted on.getServerPort in interface ServletRequestpublic boolean isSecure()
javax.servlet.ServletRequestisSecure in interface ServletRequesttrue if this request was received on a secure connection.public void removeAttribute(java.lang.String name)
removeAttribute in interface ServletRequestname - Name of the request attribute to removepublic void setAttribute(java.lang.String name,
java.lang.Object value)
setAttribute in interface ServletRequestname - Name of the request attribute to setvalue - The associated valuepublic void setCharacterEncoding(java.lang.String enc)
throws java.io.UnsupportedEncodingException
getReader().setCharacterEncoding in interface ServletRequestenc - The character encoding to be usedjava.io.UnsupportedEncodingException - if the specified encoding is not supportedpublic ServletContext getServletContext()
getServletContext in interface ServletRequestpublic AsyncContext startAsync()
startAsync in interface ServletRequestpublic AsyncContext startAsync(ServletRequest request, ServletResponse response)
startAsync in interface ServletRequestrequest - The ServletRequest with which to initialise the asynchronous contextresponse - The ServletResponse with which to initialise the asynchronous contextpublic boolean isAsyncStarted()
isAsyncStarted in interface ServletRequestpublic boolean isAsyncDispatching()
public boolean isAsyncCompleting()
public boolean isAsync()
public boolean isAsyncSupported()
isAsyncSupported in interface ServletRequestpublic AsyncContext getAsyncContext()
javax.servlet.ServletRequestgetAsyncContext in interface ServletRequestpublic AsyncContextImpl getAsyncContextInternal()
public DispatcherType getDispatcherType()
getDispatcherType in interface ServletRequestpublic void addCookie(Cookie cookie)
cookie - The new cookiepublic void addLocale(java.util.Locale locale)
locale - The new preferred Localepublic void clearCookies()
public void clearLocales()
public void setAuthType(java.lang.String type)
null. Typical
values are "BASIC", "DIGEST", or "SSL".type - The authentication type usedpublic void setPathInfo(java.lang.String path)
path - The path informationpublic void setRequestedSessionCookie(boolean flag)
flag - The new flagpublic void setRequestedSessionId(java.lang.String id)
id - The new session idpublic void setRequestedSessionURL(boolean flag)
flag - The new flagpublic void setRequestedSessionSSL(boolean flag)
flag - The new flagpublic java.lang.String getDecodedRequestURI()
public MessageBytes getDecodedRequestURIMB()
public void setUserPrincipal(java.security.Principal principal)
getRemoteUser() method.principal - The user Principalpublic boolean isTrailerFieldsReady()
javax.servlet.http.HttpServletRequesttrue if the underlying protocol does not support trailer fields. Otherwise, true is returned once
all of the following are true:
isTrailerFieldsReady in interface HttpServletRequesttrue if trailers are ready to be readpublic java.util.Map<java.lang.String,java.lang.String> getTrailerFields()
javax.servlet.http.HttpServletRequestgetTrailerFields in interface HttpServletRequestpublic PushBuilder newPushBuilder()
javax.servlet.http.HttpServletRequestPushBuilder documents how this request will be used as the
basis for a push request. Each call to this method will return a new instance, independent of any previous
instance obtained.newPushBuilder in interface HttpServletRequestnull 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.public PushBuilder newPushBuilder(HttpServletRequest request)
public <T extends HttpUpgradeHandler> T upgrade(java.lang.Class<T> httpUpgradeHandlerClass) throws java.io.IOException, ServletException
javax.servlet.http.HttpServletRequestHttpServletResponse.SC_SWITCHING_PROTOCOLS.upgrade in interface HttpServletRequestT - The type of the upgrade handlerhttpUpgradeHandlerClass - The class that implements the upgrade handlerjava.io.IOException - if an I/O error occurred during the upgradeServletException - if the given httpUpgradeHandlerClass fails to be instantiatedpublic java.lang.String getAuthType()
getAuthType in interface HttpServletRequestnull if the request was not authenticated.public java.lang.String getContextPath()
getContextPath in interface HttpServletRequestString specifying the portion of the request URI that indicates the context of the requestpublic Cookie[] getCookies()
getCookies in interface HttpServletRequestpublic ServerCookies getServerCookies()
public long getDateHeader(java.lang.String name)
getDateHeader in interface HttpServletRequestname - Name of the requested date headerjava.lang.IllegalArgumentException - if the specified header value cannot be converted to a datepublic java.lang.String getHeader(java.lang.String name)
nullgetHeader in interface HttpServletRequestname - Name of the requested headerpublic java.util.Enumeration<java.lang.String> getHeaders(java.lang.String name)
getHeaders in interface HttpServletRequestname - Name of the requested headerpublic java.util.Enumeration<java.lang.String> getHeaderNames()
javax.servlet.http.HttpServletRequest
Some servlet containers do not allow servlets to access headers using this method, in which case this method
returns null
getHeaderNames in interface HttpServletRequestpublic int getIntHeader(java.lang.String name)
getIntHeader in interface HttpServletRequestname - Name of the requested headerjava.lang.IllegalArgumentException - if the specified header value cannot be converted to an integerpublic HttpServletMapping getHttpServletMapping()
javax.servlet.http.HttpServletRequestgetHttpServletMapping in interface HttpServletRequestpublic java.lang.String getMethod()
javax.servlet.http.HttpServletRequestgetMethod in interface HttpServletRequestpublic java.lang.String getPathInfo()
javax.servlet.http.HttpServletRequest
This method returns null if there was no extra path information.
Same as the value of the CGI variable PATH_INFO.
getPathInfo in interface HttpServletRequestpublic java.lang.String getPathTranslated()
javax.servlet.http.HttpServletRequest
If the URL does not have any extra path information, this method returns null or the servlet
container cannot translate the virtual path to a real path for any reason (such as when the web application is
executed from an archive). The web container does not decode this string.
getPathTranslated in interface HttpServletRequestpublic java.lang.String getQueryString()
javax.servlet.http.HttpServletRequestnull if the URL does not have a query string. Same as the value of the CGI variable QUERY_STRING.getQueryString in interface HttpServletRequestpublic java.lang.String getRemoteUser()
javax.servlet.http.HttpServletRequestnull if
the user has not been authenticated. Whether the user name is sent with each subsequent request depends on the
browser and type of authentication. Same as the value of the CGI variable REMOTE_USER.getRemoteUser in interface HttpServletRequestpublic MessageBytes getRequestPathMB()
public java.lang.String getRequestedSessionId()
javax.servlet.http.HttpServletRequestnull.getRequestedSessionId in interface HttpServletRequestHttpServletRequest.isRequestedSessionIdValid()public java.lang.String getRequestURI()
javax.servlet.http.HttpServletRequest| First line of HTTP request | Returned Value | |
|---|---|---|
| POST /some/path.html HTTP/1.1 | /some/path.html | |
| GET http://foo.bar/a.html HTTP/1.0 | /a.html | |
| HEAD /xyz?a=b HTTP/1.1 | /xyz |
To reconstruct a URL with a scheme and host, use HttpServletRequest.getRequestURL().
getRequestURI in interface HttpServletRequestHttpServletRequest.getRequestURL()public java.lang.StringBuffer getRequestURL()
javax.servlet.http.HttpServletRequest
Because this method returns a StringBuffer, not a string, you can modify the URL easily, for
example, to append query parameters.
This method is useful for creating redirect messages and for reporting errors.
getRequestURL in interface HttpServletRequestStringBuffer object containing the reconstructed URLpublic java.lang.String getServletPath()
javax.servlet.http.HttpServletRequestThis method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.
getServletPath in interface HttpServletRequestpublic HttpSession getSession()
javax.servlet.http.HttpServletRequestgetSession in interface HttpServletRequestHttpServletRequest.getSession(boolean)public HttpSession getSession(boolean create)
javax.servlet.http.HttpServletRequestHttpSession associated with this request or, if there is no current session and
create is true, returns a new session.
If create is false and the request has no valid HttpSession, this method
returns null.
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 in interface HttpServletRequestcreate - Create a new session if one does not existHttpServletRequest.getSession()public boolean isRequestedSessionIdFromCookie()
javax.servlet.http.HttpServletRequestisRequestedSessionIdFromCookie in interface HttpServletRequesttrue if the session identifier included in this request came from a cookie.HttpServletRequest.getSession(boolean)public boolean isRequestedSessionIdFromURL()
javax.servlet.http.HttpServletRequestisRequestedSessionIdFromURL in interface HttpServletRequesttrue if the session identifier included in this request came from the request URI.HttpServletRequest.getSession(boolean)@Deprecated public boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromURL() instead.isRequestedSessionIdFromUrl in interface HttpServletRequesttrue if the session identifier included in this request came from the request URI.public boolean isRequestedSessionIdValid()
javax.servlet.http.HttpServletRequestisRequestedSessionIdValid in interface HttpServletRequesttrue if the session identifier included in this request identifies a valid session.HttpServletRequest.getRequestedSessionId(),
HttpServletRequest.getSession(boolean)public boolean isUserInRole(java.lang.String role)
javax.servlet.http.HttpServletRequestfalse.isUserInRole in interface HttpServletRequestrole - Role name to be validatedtrue if the authenticated user principal possesses the specified role name.public java.security.Principal getPrincipal()
public java.security.Principal getUserPrincipal()
javax.servlet.http.HttpServletRequestjava.security.Principal object containing the name of the current authenticated user. If
the user has not been authenticated, the method returns null.getUserPrincipal in interface HttpServletRequestpublic Session getSessionInternal()
public void changeSessionId(java.lang.String newSessionId)
newSessionId - The session to change the session ID forpublic java.lang.String changeSessionId()
javax.servlet.http.HttpServletRequestchangeSessionId in interface HttpServletRequestHttpSessionIdListenerpublic Session getSessionInternal(boolean create)
create - Create a new session if one does not existpublic boolean isParametersParsed()
true if we have parsed parameterspublic boolean isFinished()
true if an attempt has been made to read the request body and all of the request body has
been read.protected void checkSwallowInput()
public boolean authenticate(HttpServletResponse response) throws java.io.IOException, ServletException
javax.servlet.http.HttpServletRequestauthenticate in interface HttpServletRequestresponse - The response to use to return any authentication challengetrue if the user is successfully authenticated and false if notjava.io.IOException - if the authentication process attempted to read from the request or write to the
response and an I/O error occurredServletException - if the authentication failed and the caller is expected to handle the failurepublic void login(java.lang.String username,
java.lang.String password)
throws ServletException
javax.servlet.http.HttpServletRequestlogin in interface HttpServletRequestusername - The user name to authenticatepassword - The password to use to authenticate the userServletException - If any of HttpServletRequest.getRemoteUser(), HttpServletRequest.getUserPrincipal() or
HttpServletRequest.getAuthType() are non-null, if the configured authenticator does not
support user name and password authentication or if the authentication failspublic void logout()
throws ServletException
javax.servlet.http.HttpServletRequestlogout in interface HttpServletRequestServletException - If the logout failspublic java.util.Collection<Part> getParts() throws java.io.IOException, java.lang.IllegalStateException, ServletException
javax.servlet.http.HttpServletRequestgetParts in interface HttpServletRequestjava.io.IOException - if an I/O error occursjava.lang.IllegalStateException - if size limits are exceeded or no multipart configuration is providedServletException - if the request is not multipart/form-datapublic Part getPart(java.lang.String name) throws java.io.IOException, java.lang.IllegalStateException, ServletException
javax.servlet.http.HttpServletRequestgetPart in interface HttpServletRequestname - The name of the Part to obtainjava.io.IOException - if an I/O error occursjava.lang.IllegalStateException - if size limits are exceededServletException - if the request is not multipart/form-dataprotected Session doGetSession(boolean create)
protected java.lang.String unescape(java.lang.String s)
protected void parseCookies()
protected void convertCookies()
protected void parseParameters()
@Deprecated
protected int readPostBody(byte[] body,
int len)
throws java.io.IOException
readPostBodyFully(byte[], int)body - The bytes array in which the body will be readlen - The body lengthjava.io.IOException - if an IO exception occurredprotected void readPostBodyFully(byte[] body,
int len)
throws java.io.IOException
body - The bytes array in which the body will be readlen - The body lengthjava.io.IOException - if an IO exception occurred or EOF is reached before the body has been fully readprotected byte[] readChunkedPostBody()
throws java.io.IOException
java.io.IOException - if an IO exception occurredprotected void parseLocales()
protected void parseLocalesHeader(java.lang.String value,
java.util.TreeMap<java.lang.Double,java.util.ArrayList<java.util.Locale>> locales)
value - the header valuelocales - the map that will hold the resultCopyright © 2000-2024 Apache Software Foundation.
Apache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo are either registered trademarks or trademarks of the Apache Software Foundation.