public interface HttpServletRequest extends ServletRequest
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BASIC_AUTH
Identifier for a request using basic authentication.
|
static java.lang.String |
CLIENT_CERT_AUTH
Indentifier for a request using client certificate authentication
value is "CLIENT_CERT"
|
static java.lang.String |
DIGEST_AUTH
Indentifier for a request using digest authentication
value is "DIGEST"
|
static java.lang.String |
FORM_AUTH
Identifier for a request using form authentication.
|
Modifier and Type | Method and Description |
---|---|
boolean |
authenticate(HttpServletResponse response)
Authenticate the user making this request.
|
java.lang.String |
getAuthType()
Gets the authorization scheme of this request.
|
java.lang.String |
getContextPath()
Returns the part of the request path used to identify the servlet context.
|
Cookie[] |
getCookies()
Gets all the Cookies present in the request.
|
long |
getDateHeader(java.lang.String name)
Converts a given header parameter name to a date in the form of
the number of milliseconds since 1 january 1970 midnight GMT.
|
java.lang.String |
getHeader(java.lang.String name)
Gets a named header.
|
java.util.Enumeration |
getHeaderNames()
Gets an Enumeration with all the headernames.
|
java.util.Enumeration |
getHeaders(java.lang.String name)
Returns the values of the specified header as an enumeration of String.
|
int |
getIntHeader(java.lang.String name)
Gets a named header and returns it in the shape of an int.
|
java.lang.String |
getMethod()
Gets the method the client used.
|
Part |
getPart(java.lang.String name)
Returns the part with the specified name.
|
java.util.Collection<Part> |
getParts()
Returns all of the
Part components of this
multipart/form-data request. |
java.lang.String |
getPathInfo()
Extra path info.
|
java.lang.String |
getPathTranslated()
The filesystem path to the path info.
|
java.lang.String |
getQueryString()
Gets the request's query string.
|
java.lang.String |
getRemoteUser()
Gets the username of the person sending the request.
|
java.lang.String |
getRequestedSessionId()
Gets the session Id of this request that the client wanted.
|
java.lang.String |
getRequestURI()
Gets the requested URI.
|
java.lang.StringBuffer |
getRequestURL()
Contains the URL that the client used to make the request without
the query string.
|
java.lang.String |
getServletPath()
Gets the part of the URI up to and including the servlet name.
|
HttpSession |
getSession()
Gets the HttpSession connected with the client sending the request.
|
HttpSession |
getSession(boolean create)
Gets the HttpSession connected with the client sending the request.
|
java.security.Principal |
getUserPrincipal()
get the principal associated with the user tied to this request.
|
boolean |
isRequestedSessionIdFromCookie()
was the session id in the request passed via a Cookie.
|
boolean |
isRequestedSessionIdFromUrl()
Deprecated.
|
boolean |
isRequestedSessionIdFromURL()
was the session id in the request passed via encoding of the request URI.
|
boolean |
isRequestedSessionIdValid()
is the session connected with the id in the request valid?
A session id is valid if it came in with the current request and
the session associated with it exists and is valid.
|
boolean |
isUserInRole(java.lang.String role)
is the user in the specified HTTP role?
|
void |
login(java.lang.String username,
java.lang.String password)
Validate the specified username and password against the realm for
this context.
|
void |
logout()
Remove userPrincipal, remoteUser, and authType from the request.
|
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
static final java.lang.String BASIC_AUTH
static final java.lang.String FORM_AUTH
static final java.lang.String CLIENT_CERT_AUTH
static final java.lang.String DIGEST_AUTH
java.lang.String getAuthType()
AUTH_TYPE
.
See also section 11 of the HTTP/1.1 specification (RFC 2068).Cookie[] getCookies()
long getDateHeader(java.lang.String name)
name
- the name of the header field (case insensitive)java.lang.IllegalArgumentException
- if the value is not a datejava.lang.String getHeader(java.lang.String name)
name
- the name of the header field (case insensitive)java.util.Enumeration getHeaders(java.lang.String name)
java.util.Enumeration getHeaderNames()
int getIntHeader(java.lang.String name)
name
- the name of the header field (case insensitive)java.lang.NumberFormatException
- if the headervalue can't be converted
to an int.java.lang.String getMethod()
REQUEST_METHOD
.
Possible return values are "GET", "HEAD", "POST", "PUT", "DELETE",
"OPTIONS", "TRACE".java.lang.String getPathInfo()
PATH_INFO
and identifies the source or sub-resource to be returned by the Servlet.
The function of this method could best be explained using an example.
Client requests: www.foo_bar.com/servlets/myServlet/more/path?id=paul
(where myServlet is a servlet)
In this case this method would return "/more/path".
[MJW] Note that the Servlet 2.1 Spec says that the path info must be URL
decoded although this was not required before 2.1 and I am not sure if
that is the behaviour of the CGI request metadata PATH_INFO
.
java.lang.String getPathTranslated()
PATH_TRANSLATED
.
[MJW] Can this be different from calling
ServletContext.getRealPath()
on the urldecoded result of
getPathInfo()
?
java.lang.String getContextPath()
java.lang.String getQueryString()
QUERY_STRING
.java.lang.String getRemoteUser()
REMOTE_USER
.boolean isUserInRole(java.lang.String role)
java.security.Principal getUserPrincipal()
java.lang.String getRequestedSessionId()
java.lang.String getRequestURI()
Note that the Servlet 2.1 Spec says that the URI must be decoded before being returned, but this was not required before the Servlet 2.1 API and normally all URIs are encoded.
java.lang.StringBuffer getRequestURL()
java.lang.String getServletPath()
SCRIPT_NAME
.HttpSession getSession()
getSession(true)
.HttpSession getSession(boolean create)
create
is true then a new HttpSession will be
created. If create
is false then null
is returned. To maintain a session this
method must be called before the connection is flushed or closed.boolean isRequestedSessionIdValid()
Note: there is no other way to test session validity than using this method.
boolean isRequestedSessionIdFromCookie()
boolean isRequestedSessionIdFromURL()
boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromURL()
boolean authenticate(HttpServletResponse response) throws java.io.IOException, ServletException
java.io.IOException
ServletException
void login(java.lang.String username, java.lang.String password) throws ServletException
ServletException
- on login failurevoid logout() throws ServletException
ServletException
java.util.Collection<Part> getParts() throws java.io.IOException, ServletException
Part
components of this
multipart/form-data request.ServletException
- if this request is not of type
multipart/form-datajava.lang.IllegalArgumentException
- if the request body is larger
than maxRequestSize or any part body is larger than maxFileSizejava.io.IOException
Part getPart(java.lang.String name) throws java.io.IOException, ServletException
ServletException
- if this request is not of type
multipart/form-datajava.lang.IllegalArgumentException
- if the request body is larger
than maxRequestSize or the part body is larger than maxFileSizejava.io.IOException