Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
120
Chapter 5 Accessing the Standard CGI Variables
Listing 5.1 ShowCGIVariables.java (continued)
{ "DOCUMENT_ROOT",
getServletContext().getRealPath("/") },
{ "PATH_INFO", request.getPathInfo() },
{ "PATH_TRANSLATED", request.getPathTranslated() },
{ "QUERY_STRING", request.getQueryString() },
{ "REMOTE_ADDR", request.getRemoteAddr() },
{ "REMOTE_HOST", request.getRemoteHost() },
{ "REMOTE_USER", request.getRemoteUser() },
{ "REQUEST_METHOD", request.getMethod() },
{ "SCRIPT_NAME", request.getServletPath() },
{ "SERVER_NAME", request.getServerName() },
{ "SERVER_PORT",
String.valueOf(request.getServerPort()) },
{ "SERVER_PROTOCOL", request.getProtocol() },
{ "SERVER_SOFTWARE",
getServletContext().getServerInfo() }
};
String title = "Servlet Example: Showing CGI Variables";
out.println(ServletUtilities.headWithTitle(title) +
"\n" +
"" + title + "
\n" +
"\n" +
"\n" +
"CGI Variable Name | Value");
for(int i=0; i
String varName = variables[i][0];
String varValue = variables[i][1];
if (varValue == null)
varValue = "Not specified";
out.println("" + varName + " | " + varValue);
}
out.println(" | |