Js
Package coreservlets;
Import java.io.*;
Import javax.servlet.*;
Import javax.servlet.http.*;
Import java.util.*;
/** creates a table showing the current value of each
* of the standard CGI variables.
* <P>
* Taken from Core Servlets and JavaServer Pages
* FROM Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
*©2000 Marty Hall; May is freely used or adapted.
*/
public class Showcgivariables extends HttpServlet {
public void doget (HttpServletRequest request,
HttpServletResponse response)
Throws Servletexception, IOException {
Response.setcontenttype ("text/html");
PrintWriter out = Response.getwriter ();
string[][] variables =
{{"Auth_type", Request.getauthtype ()},
{"Content_length",
String.valueof (Request.getcontentlength ())},
{"Content_Type", Request.getcontenttype ()},
{"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 (title) + Servletutilities.headwithtitle
"<body bgcolor=\" #FDF5E6 \ ">\n" +
"
"<table border=1 align=\" Center\ ">\n" +
"<tr bgcolor=\" #FFAD00 \ ">\n" +
"<th>cgi Variable name<th>value");
for (int i=0; i<variables.length; i++) {
String varName = variables[0];
String varvalue = variables[i][1];
if (Varvalue = null)
Varvalue = "<i>not specified</i>";
Out.println ("<TR><TD>" + varName + "<TD>" + varvalue);
}
Out.println ("</TABLE></BODY></HTML>");
}
/** POST and get requests handled identically. */
public void DoPost (HttpServletRequest request,
HttpServletResponse response)
Throws Servletexception, IOException {
Doget (request, response);
}
}