public interface HttpServletRequest extends ServletRequest
For example, given an application prefix of '/myapp', the api
/myapp/dir/test.jsp/data
will be split as follows:
/myapp/dir/test.jsp/data | getRequestURI() |
/myapp | getContextPath() |
/dir/test.jsp | getServletPath() |
/data | getPathInfo() |
User-Agent | String describing the browser's version |
AUTH_TYPE | getAuthType() |
CONTENT_TYPE | getContentType() |
CONTENT_LENGTH | getContentLength() |
PATH_INFO | getPathInfo() |
PATH_TRANSLATED | getPathTranslated() |
QUERY_STRING | getQueryString() |
REMOTE_ADDR | getRemoteAddr() |
REMOTE_HOST | getRemoteHost() |
REMOTE_USER | getRemoteUser() |
REQUEST_METHOD | getMethod() |
SCRIPT_NAME | getServletPath() |
SERVER_NAME | getServerName() |
SERVER_PROTOCOL | getProtocol() |
SERVER_PORT | getServerPort() |
ServletRequest.getParameter()
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BASIC_AUTH
String identifier for basic authentication.
|
static java.lang.String |
CLIENT_CERT_AUTH
String identifier for client cert authentication.
|
static java.lang.String |
DIGEST_AUTH
String identifier for digest authenciation.
|
static java.lang.String |
FORM_AUTH
String identifier for form authenciation.
|
Modifier and Type | Method and Description |
---|---|
boolean |
authenticate(HttpServletResponse response) |
java.lang.String |
getAuthType()
Returns the auth type, i.e.
|
java.lang.String |
getContextPath()
Returns the part of the URI corresponding to the application's
prefix.
|
Cookie[] |
getCookies()
Returns an array of all cookies sent by the client.
|
long |
getDateHeader(java.lang.String name)
Converts a date header to milliseconds since the epoch.
|
java.lang.String |
getHeader(java.lang.String name)
Returns the first value for a request header.
|
java.util.Enumeration<java.lang.String> |
getHeaderNames()
Returns an enumeration of all headers sent by the client.
|
java.util.Enumeration<java.lang.String> |
getHeaders(java.lang.String name)
Returns all the values for a request header.
|
int |
getIntHeader(java.lang.String name)
Converts a header value to an integer.
|
java.lang.String |
getMethod()
Returns the HTTP method, e.g.
|
Part |
getPart(java.lang.String name) |
java.util.Collection<Part> |
getParts() |
java.lang.String |
getPathInfo()
Returns the URI part after the selected servlet and null if there
is no suffix.
|
java.lang.String |
getPathTranslated()
Returns the physical path name for the path info.
|
java.lang.String |
getQueryString()
Returns the request's query string.
|
java.lang.String |
getRemoteUser()
Returns the remote user if authenticated.
|
java.lang.String |
getRequestedSessionId()
Returns the session id.
|
java.lang.String |
getRequestURI()
Returns the entire request URI
|
java.lang.StringBuffer |
getRequestURL()
Reconstructs the URL the client used for the request.
|
java.lang.String |
getServletPath()
Returns the URI part corresponding to the selected servlet.
|
HttpSession |
getSession()
Returns the current session, creating one if necessary.
|
HttpSession |
getSession(boolean create)
Returns a session.
|
java.security.Principal |
getUserPrincipal()
Returns the equivalent principal object for the authenticated user.
|
boolean |
isRequestedSessionIdFromCookie()
Returns true if the session came from a cookie.
|
boolean |
isRequestedSessionIdFromUrl()
Deprecated.
|
boolean |
isRequestedSessionIdFromURL()
Returns true if the session came URL-encoding.
|
boolean |
isRequestedSessionIdValid()
Returns true if the session is valid.
|
boolean |
isUserInRole(java.lang.String role)
Returns true if the user is in the given role.
|
void |
login(java.lang.String username,
java.lang.String password) |
void |
logout() |
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 CLIENT_CERT_AUTH
static final java.lang.String DIGEST_AUTH
static final java.lang.String FORM_AUTH
java.lang.String getMethod()
REQUEST_METHOD
java.lang.String getRequestURI()
java.lang.StringBuffer getRequestURL()
java.lang.String getContextPath()
getContextPath()
is /myapp for the uri
/myapp/servlet/Hello,
java.lang.String getServletPath()
SCRIPT_NAME
getServletPath()
is /servlet/Hello for the uri
/myapp/servlet/Hello/foo.
getServletPath()
is /dir/hello.jsp
for the uri /myapp/dir/hello.jsp/foo,java.lang.String getPathInfo()
PATH_INFO
getPathInfo()
is /foo for
the uri /myapp/servlet/Hello/foo.
getPathInfo()
is /hello.jsp for for the uri
/myapp/dir/hello.jsp/foo.
java.lang.String getPathTranslated()
PATH_TRANSLATED
java.lang.String getQueryString()
ServletRequest.getParameter()
to decode the form values.
Corresponds to CGI's PATH_TRANSLATED
java.lang.String getHeader(java.lang.String name)
HTTP_*
String userAgent = request.getHeader("User-Agent");
name
- the header namejava.util.Enumeration<java.lang.String> getHeaders(java.lang.String name)
name
- the header namejava.util.Enumeration<java.lang.String> getHeaderNames()
int getIntHeader(java.lang.String name)
name
- the header namelong getDateHeader(java.lang.String name)
long mod = request.getDateHeader("If-Modified-Since");
name
- the header nameCookie[] getCookies()
HttpSession getSession(boolean create)
create
- If true, then create a new session if none exists.HttpSession getSession()
java.lang.String getRequestedSessionId()
boolean isRequestedSessionIdValid()
boolean isRequestedSessionIdFromCookie()
boolean isRequestedSessionIdFromURL()
java.lang.String getAuthType()
java.lang.String getRemoteUser()
boolean isUserInRole(java.lang.String role)
java.security.Principal getUserPrincipal()
boolean 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
void logout() throws ServletException
ServletException
java.util.Collection<Part> getParts() throws java.io.IOException, ServletException
java.io.IOException
ServletException
Part getPart(java.lang.String name) throws java.io.IOException, ServletException
java.io.IOException
ServletException