The following servlet code becomes a JSP roughly ...

Source: Internet
Author: User
Js|servlet import java.io.*;
Import javax.servlet.*;
Import javax.servlet.http.*;
Import java.util.*;

/** shows 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 JavaServer Pages
* FROM Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
*©2000 Marty Hall; May is 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 (title) + Servletutilities.headwithtitle
"<body bgcolor=\" #FDF5E6 \ ">\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);
}
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.