This page discusses
how you retrieve CGI variables should you wish to access.
- CGI varaibles are
in part taken from HTTP
request headers, and server and client machine information.
|
|
CGI Variable |
How to Access in Servlet
r = instance of HttpServletRequest |
AUTH_TYPE |
- Gives scheme specified (basic or digest)
- r.getAuthType();
|
CONTENT_LENGTH |
- For POST only, gives # bytes of data sent
- r.getContentLength() = returns int, convert
to String to get same type as CONTENT_LENGTH
|
CONTENT_TYPE |
- MIME type of data being sent.
- r.getContentType()
|
DOCUMENT_ROOT |
- Specifies real directory of the URL
- r.getRealPath()
|
HTTP_XXX_YYY |
- This describes series of HTTP request header variables like
HTTP_COOKIE, HTTP_USER_AGENT, etc.
- Access either via r.getHeader("Cookie"), etc.
or use direct methods if exis r.getCookies().
See info on HTTP Request
Headers.
|
PATH_INFO |
- Specifies path of URL
- r.getPathInfo()
|
QUERY_STRING |
- For GET requests, gives query data at the end of the URL
- r.getParameter("name") can be used most efficiently
to get the parsed value.
- r.getQueryString() can be used to get the entire
query data string in unparsed format.
|
REMOTE_ADDR |
- gives IP address of client making request
- r.getRemoteAddr()
|
REMOTE_HOST |
- gives domain name of client
- r.getRemoteHost()
|
REMOTE_USER |
- If an Authorization Header (see HTTP
request headers) was specified, gives the user part.
- r.getRemoteUser()
|
REQUEST_METHOD |
- stipulates HTTP request type, e.g. GET, POST, PUT, DELETE,
etc.
- r.getMethod()
|
SCRIPT_NAME |
- gives path to servlet
- r.getServletPath()
|
SERVER_NAME |
- gives host of server
- r.getServerName()
|
SERVER_PORT |
- gives port server on
- r.getServerPort()
|
SERVER_PROTOCOL |
- tells protocol and version used on server, (e.g. HTTP/1.1,
etc)
- r.getProtocol()
|
SERVER_SOFTWARE |
- tells about id of Web-server
- getServletContext().getServerInfo()
- this is method of HttpServlet class!!!
|