javax.servlet.http
Interface HttpServletRequest


public interface HttpServletRequest
extends ServletRequest

HttpServletRequest encapsulates client request data.

URI

The servlet engine splits the URI into three useful sections: the context path (application prefix), the servlet path, and the path info.

For example, given an application prefix of '/myapp', the api /myapp/dir/test.jsp/data will be split as follows:
/myapp/dir/test.jsp/datagetRequestURI()
/myappgetContextPath()
/dir/test.jspgetServletPath()
/datagetPathInfo()

Useful headers

User-AgentString describing the browser's version

Form data

For form data, see ServletRequest.getParameter()


Method Summary
 java.lang.String getAuthType()
          Returns the auth type, e.g.
 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 getHeaderNames()
          Returns an enumeration of all headers sent by the client.
 java.util.Enumeration 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.
 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.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.
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getParameter, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute
 

Method Detail

getMethod

public java.lang.String getMethod()
Returns the HTTP method, e.g. "GET" or "POST"

getRequestURI

public java.lang.String getRequestURI()
Returns the entire request URI

getContextPath

public java.lang.String getContextPath()
Returns the part of the URI corresponding to the application's prefix. The first part of the URI selects applications (ServletContexts).

getContextPath() is /myapp for the uri /myapp/servlet/Hello,


getServletPath

public java.lang.String getServletPath()
Returns the URI part corresponding to the selected servlet. The URI is relative to the application. getServletPath() is /servlet/Hello for the uri /myapp/servlet/Hello/foo. getServletPath() is /dir/hello.jsp for the uri /myapp/dir/hello.jsp/foo,

getPathInfo

public java.lang.String getPathInfo()
Returns the URI part after the selected servlet and null if there is no suffix.

getPathInfo() is /foo for the uri /myapp/servlet/Hello/foo. getPathInfo() is /hello.jsp for for the uri /myapp/dir/hello.jsp/foo.


getPathTranslated

public java.lang.String getPathTranslated()
Returns the physical path name for the path info.
Returns:
null if there is no path info.

getQueryString

public java.lang.String getQueryString()
Returns the request's query string. To decode the query string use ServletRequest.getParameter()

getHeader

public java.lang.String getHeader(java.lang.String name)
Returns the first value for a request header.
Parameters:
name - the header name
Returns:
the header value

getHeaders

public java.util.Enumeration getHeaders(java.lang.String name)
Returns all the values for a request header. In some rare cases, like cookies, browsers may return multiple headers.
Parameters:
name - the header name
Returns:
an enumeration of the header values.

getHeaderNames

public java.util.Enumeration getHeaderNames()
Returns an enumeration of all headers sent by the client.

getIntHeader

public int getIntHeader(java.lang.String name)
Converts a header value to an integer.
Parameters:
name - the header name
Returns:
the header value converted to an integer

getDateHeader

public long getDateHeader(java.lang.String name)
Converts a date header to milliseconds since the epoch.

 long mod = request.getDateHeader("If-Modified-Since");
 
Parameters:
name - the header name
Returns:
the header value converted to an date

getCookies

public Cookie[] getCookies()
Returns an array of all cookies sent by the client.

getSession

public HttpSession getSession(boolean create)
Returns a session. If no session exists and create is true, then create a new session, otherwise return null.
Parameters:
create - If true, then create a new session if none exists.

getSession

public HttpSession getSession()
Returns the current session, creating one if necessary.

getRequestedSessionId

public java.lang.String getRequestedSessionId()
Returns the session id.

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Returns true if the session is valid.

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Returns true if the session came from a cookie.

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Returns true if the session came URL-encoding.

getAuthType

public java.lang.String getAuthType()
Returns the auth type, e.g. basic.

getRemoteUser

public java.lang.String getRemoteUser()
Returns the remote user if authenticated.

isUserInRole

public boolean isUserInRole(java.lang.String role)
Returns true if the user is in the given role.

getUserPrincipal

public java.security.Principal getUserPrincipal()
Returns the equivalent principal object for the authenticated user.

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Deprecated.