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 + ""<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> }
Public void dopost (httpservletrequest request,
httpservletresponse response)
throws servletexception, ioexception {
doget (request, response );
}< BR >}