Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Interface javax.servlet.http.HttpServletRequest


public 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
String  getAuthType()
Gets the authentication scheme of this request.
Cookie[]  getCookies()
Gets the array of cookies found in this request.
long  getDateHeader(String name)
Gets the value of the requested date header field of this request.
String  getHeader(String name)
Gets the value of the requested header field of this request.
Enumeration  getHeaderNames()
Gets the header names for this request.
int  getIntHeader(String name)
Gets the value of the specified integer header field of this request.
String  getMethod()
Gets the HTTP method (for example, GET, POST, PUT) with which this request was made.
String  getPathInfo()
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string.
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.
String  getQueryString()
Gets any query string that is part of the HTTP request URI.
String  getRemoteUser()
Gets the name of the user making this request.
String  getRequestedSessionId()
Gets the session id specified with this request.
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.
String  getServletPath()
Gets the part of this request's URI that refers to the servlet being invoked.
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()
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.
 

Method Detail

getCookies

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

getMethod

public 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

getRequestURI

public 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:
getRequestURL

getServletPath

public 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

getPathInfo

public 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 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 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 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.

getAuthType

public 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.

getHeader

public String getHeader(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.

getIntHeader

public int getIntHeader(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.

getDateHeader

public long getDateHeader(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.

getHeaderNames

public 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.

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.

getRequestedSessionId

public 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

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

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

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

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.