1+
12// Import required java libraries
23import java .io .*;
34import javax .servlet .*;
67
78// Extend HttpServlet class
89public class ReadParams extends HttpServlet {
9-
10+
1011 /**
11- *
12- */
13- private static final long serialVersionUID = 1L ;
12+ *
13+ */
14+ private static final long serialVersionUID = 1L ;
1415
15- // Method to handle GET method request.
16+ // Method to handle GET method request.
1617 public void doGet (HttpServletRequest request , HttpServletResponse response )
17- throws ServletException , IOException {
18-
18+ throws ServletException , IOException {
19+
1920 // Set response content type
2021 response .setContentType ("text/html" );
2122
2223 PrintWriter out = response .getWriter ();
2324 String title = "Reading All Form Parameters" ;
24- String docType =
25- "<!doctype html public \" -//w3c//dtd html 4.0 " + "transitional//en\" >\n " ;
25+ String docType = "<!doctype html public \" -//w3c//dtd html 4.0 " + "transitional//en\" >\n " ;
2626
2727 out .println (docType +
28- "<html>\n " +
29- "<head><title>" + title + "</title></head>\n " +
30- "<body bgcolor = \" #f0f0f0\" >\n " +
31- "<h1 align = \" center\" >" + title + "</h1>\n " +
32- "<table width = \" 100%\" border = \" 1\" align = \" center\" >\n " +
33- "<tr bgcolor = \" #949494\" >\n " +
28+ "<html>\n " +
29+ "<head><title>" + title + "</title></head>\n " +
30+ "<body bgcolor = \" #f0f0f0\" >\n " +
31+ "<h1 align = \" center\" >" + title + "</h1>\n " +
32+ "<table width = \" 100%\" border = \" 1\" align = \" center\" >\n " +
33+ "<tr bgcolor = \" #949494\" >\n " +
3434 "<th>Param Name</th>" +
35- "<th>Param Value(s)</th>\n " +
36- "</tr>\n "
37- );
35+ "<th>Param Value(s)</th>\n " +
36+ "</tr>\n " );
3837
3938 Enumeration paramNames = request .getParameterNames ();
4039
41- while (paramNames .hasMoreElements ()) {
42- String paramName = (String )paramNames .nextElement ();
40+ while (paramNames .hasMoreElements ()) {
41+ String paramName = (String ) paramNames .nextElement ();
4342 out .print ("<tr><td>" + paramName + "</td>\n <td>" );
4443 String [] paramValues = request .getParameterValues (paramName );
4544
@@ -48,25 +47,25 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
4847 String paramValue = paramValues [0 ];
4948 if (paramValue .length () == 0 )
5049 out .println ("<i>No Value</i>" );
51- else
50+ else
5251 out .println (paramValue );
5352 } else {
5453 // Read multiple valued data
5554 out .println ("<ul>" );
5655
57- for (int i = 0 ; i < paramValues .length ; i ++) {
56+ for (int i = 0 ; i < paramValues .length ; i ++) {
5857 out .println ("<li>" + paramValues [i ]);
5958 }
6059 out .println ("</ul>" );
6160 }
6261 }
6362 out .println ("</tr>\n </table>\n </body></html>" );
6463 }
65-
64+
6665 // Method to handle POST method request.
6766 public void doPost (HttpServletRequest request , HttpServletResponse response )
68- throws ServletException , IOException {
69-
67+ throws ServletException , IOException {
68+
7069 doGet (request , response );
7170 }
7271}
0 commit comments