Package coreservlets;
Import java. io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Import java. util .*;
/** Shows all the parameters sent to the servlet via either
* GET or POST. Specially marks parameters that have
* No values or multiple values.
* <P>
* Taken from Core Servlets and assumerver Pages
* From Prentice Hall and Sun Microsystems Press,
* Http://www.coreservlets.com /.
*©2000 Marty Hall; may be freely used or adapted.
*/
Public class ShowParameters extends HttpServlet {
Public void doGet (HttpServletRequest request,
HttpServletResponse response)
Throws ServletException, IOException {
Response. setContentType ("text/html ");
PrintWriter out = response. getWriter ();
String title = "Reading All Request Parameters ";
Out. println (ServletUtilities. headWithTitle (title) +
"<Body bgcolor = \" # FDF5E6 \ "> \ n" +
"<H1 ALIGN = CENTER>" + title + "</H1> \ n" +
"<Table border = 1 ALIGN = CENTER> \ n" +
"<Tr bgcolor = \" # FFAD00 \ "> \ n" +
"<TH> Parameter Name <TH> Parameter Value (s )");
Enumeration paramNames = request. getParameterNames ();
While (paramNames. hasMoreElements ()){
String paramName = (String) paramNames. nextElement ();
Out. print ("<TR> <TD>" + paramName + "\ n <TD> ");
String [] paramValues =
Request. getParameterValues (paramName );
If (paramValues. length = 1 ){
String paramValue = paramValues [0];
If (paramValue. length () = 0)
Out. println ("<I> No Value </I> ");
Else
Out. println (paramValue );
} Else {
Out. println ("<UL> ");
For (int I = 0; I <paramValues. length; I ++ ){
Out. println ("<LI>" + paramValues );
}
Out. println ("</UL> ");
}
}
Out. println ("</TABLE> \ n </BODY> </HTML> ");
}
Public void doPost (HttpServletRequest request,
HttpServletResponse response)
Throws ServletException, IOException {
DoGet (request, response );
}
}