javax.servlet.http
Interface HttpServletRequest


public abstract interface HttpServletRequest
extends ServletRequest

An HTTP servlet request. This interface gets data from the client to the servlet for use in the HttpServlet.service method. It allows the HTTP-protocol specified header information to be accessed from the service method. This interface is implemented by network-service developers for use within servlets.


Method Summary
 java.lang.String getAuthType()
          Gets the authentication scheme of this request.
 Cookie[] getCookies()
          Gets the array of cookies found in this request.
 long getDateHeader(java.lang.String name)
          Gets the value of the requested date header field of this request.
 java.lang.String getHeader(java.lang.String name)
          Gets the value of the requested header field of this request.
 java.util.Enumeration getHeaderNames()
          Gets the header names for this request.
 int getIntHeader(java.lang.String name)
          Gets the value of the specified integer header field of this request.
 java.lang.String getMethod()
          Gets the HTTP method (for example, GET, POST, PUT) with which this request was made.
 java.lang.String getPathInfo()
          Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string.
 java.lang.String getPathTranslated()
          Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string, and translates it to a real path.
 java.lang.String getQueryString()
          Gets any query string that is part of the HTTP request URI.
 java.lang.String getRemoteUser()
          Gets the name of the user making this request.
 java.lang.String getRequestedSessionId()
          Gets the session id specified with this request.
 java.lang.String getRequestURI()
          Gets, from the first line of the HTTP request, the part of this request's URI that is to the left of any query string.
 java.lang.String getServletPath()
          Gets the part of this request's URI that refers to the servlet being invoked.
 HttpSession getSession()
          Gets the current valid session associated with this request, if create is false or, if necessary, creates a new session for the request.
 HttpSession getSession(boolean create)
          Gets the current valid session associated with this request, if create is false or, if necessary, creates a new session for the request, if create is true.
 boolean isRequestedSessionIdFromCookie()
          Checks whether the session id specified by this request came in as a cookie.
 boolean isRequestedSessionIdFromUrl()
          Deprecated. use isRequestSessionIdFromURL() instead
 boolean isRequestedSessionIdFromURL()
          Checks whether the session id specified by this request came in as part of the URL.
 boolean isRequestedSessionIdValid()
          Checks whether this request is associated with a session that is valid in the current session context.
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getParameter, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getScheme, getServerName, getServerPort, setAttribute
 

Method Detail

getAuthType

public java.lang.String getAuthType()
Gets the authentication scheme of this request. Same as the CGI variable AUTH_TYPE.
Returns:
this request's authentication scheme, or null if none.

getCookies

public Cookie[] getCookies()
Gets the array of cookies found in this request.
Returns:
the array of cookies found in this request

getDateHeader

public long getDateHeader(java.lang.String name)
Gets the value of the requested date header field of this request. If the header can't be converted to a date, the method throws an IllegalArgumentException. The case of the header field name is ignored.
Parameters:
name - the String containing the name of the requested header field
Returns:
the value the requested date header field, or -1 if not found.

getHeader

public java.lang.String getHeader(java.lang.String name)
Gets the value of the requested header field of this request. The case of the header field name is ignored.
Parameters:
name - the String containing the name of the requested header field
Returns:
the value of the requested header field, or null if not known.

getHeaderNames

public java.util.Enumeration getHeaderNames()
Gets the header names for this request.
Returns:
an enumeration of strings representing the header names for this request. Some server implementations do not allow headers to be accessed in this way, in which case this method will return null.

getIntHeader

public int getIntHeader(java.lang.String name)
Gets the value of the specified integer header field of this request. The case of the header field name is ignored. If the header can't be converted to an integer, the method throws a NumberFormatException.
Parameters:
name - the String containing the name of the requested header field
Returns:
the value of the requested header field, or -1 if not found.

getMethod

public java.lang.String getMethod()
Gets the HTTP method (for example, GET, POST, PUT) with which this request was made. Same as the CGI variable REQUEST_METHOD.
Returns:
the HTTP method with which this request was made

getPathInfo

public java.lang.String getPathInfo()
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string. Same as the CGI variable PATH_INFO.
Returns:
the optional path information following the servlet path, but before the query string, in this request's URI; null if this request's URI contains no extra path information

getPathTranslated

public java.lang.String getPathTranslated()
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string, and translates it to a real path. Same as the CGI variable PATH_TRANSLATED.
Returns:
extra path information translated to a real path or null if no extra path information is in the request's URI

getQueryString

public java.lang.String getQueryString()
Gets any query string that is part of the HTTP request URI. Same as the CGI variable QUERY_STRING.
Returns:
query string that is part of this request's URI, or null if it contains no query string

getRemoteUser

public java.lang.String getRemoteUser()
Gets the name of the user making this request. The user name is set with HTTP authentication. Whether the user name will continue to be sent with each subsequent communication is browser-dependent. Same as the CGI variable REMOTE_USER.
Returns:
the name of the user making this request, or null if not known.

getRequestedSessionId

public java.lang.String getRequestedSessionId()
Gets the session id specified with this request. This may differ from the actual session id. For example, if the request specified an id for an invalid session, then this will get a new session with a new id.
Returns:
the session id specified by this request, or null if the request did not specify a session id
See Also:
isRequestedSessionIdValid()

getRequestURI

public java.lang.String getRequestURI()
Gets, from the first line of the HTTP request, the part of this request's URI that is to the left of any query string. For example,
First line of HTTP request Return from getRequestURI
POST /some/path.html HTTP/1.1/some/path.html
GET http://foo.bar/a.html HTTP/1.0 http://foo.bar/a.html
HEAD /xyz?a=b HTTP/1.1/xyz

To reconstruct a URL with a URL scheme and host, use the method javax.servlet.http.HttpUtils.getRequestURL, which returns a StringBuffer.

Returns:
this request's URI
See Also:
HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest)

getServletPath

public java.lang.String getServletPath()
Gets the part of this request's URI that refers to the servlet being invoked. Analogous to the CGI variable SCRIPT_NAME.
Returns:
the servlet being invoked, as contained in this request's URI

getSession

public HttpSession getSession(boolean create)
Gets the current valid session associated with this request, if create is false or, if necessary, creates a new session for the request, if create is true.

Note: to ensure the session is properly maintained, the servlet developer must call this method (at least once) before any output is written to the response.

Additionally, application-writers need to be aware that newly created sessions (that is, sessions for which HttpSession.isNew returns true) do not have any application-specific state.

Returns:
the session associated with this request or null if create was false and no valid session is associated with this request.

getSession

public HttpSession getSession()
Gets the current valid session associated with this request, if create is false or, if necessary, creates a new session for the request.

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Checks whether this request is associated with a session that is valid in the current session context. If it is not valid, the requested session will never be returned from the getSession method.
Returns:
true if this request is assocated with a session that is valid in the current session context.
See Also:
getRequestedSessionId(), HttpSessionContext, getSession(boolean)

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Checks whether the session id specified by this request came in as a cookie. (The requested session may not be one returned by the getSession method.)
Returns:
true if the session id specified by this request came in as a cookie; false otherwise
See Also:
getSession(boolean)

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Checks whether the session id specified by this request came in as part of the URL. (The requested session may not be the one returned by the getSession method.)
Returns:
true if the session id specified by the request for this session came in as part of the URL; false otherwise
See Also:
getSession(boolean)

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Deprecated. use isRequestSessionIdFromURL() instead
Checks whether the session id specified by this request came in as part of the URL. (The requested session may not be the one returned by the getSession method.)
Returns:
true if the session id specified by the request for this session came in as part of the URL; false otherwise
See Also:
getSession(boolean)