Hi Everyone!
There is a servlet i found from a book that utilizes the parameters from 
servlets but whenever i run it the browser doesnt seem to open the class 
properly and instead it only downloads the .class file. I think the problem 
here has something to do with the new Tomcat version. Can someone try 
deploying the application so that I'll be able to find out whether what the 
problem really is. Below are the codes i used:

the code below is for Form.html where i have to enter the information that 
will be passed onto the servlet:
<HTML>
<HEAD>
<TITLE>
Parameter Servlet Form
</TITLE>
</HEAD>
<BODY>

<form
action="servlet/chapter2.ParameterServlet"
method=POST>
<table width="400" border="0" cellspacing="0">
<tr>
<td>Name: </td>
<td>
<input type="text"
name="name"
size="20"
maxlength="20"
</td>
<td>SSN:</td>
<td>
<input type="text" name="ssn" size="11" maxlength="11">
</td>
</tr>
<tr>
<td>Age:</td>
<td>
<input type="text" name="age" size="3" maxlength="3">
</td>
<td>email:</td>
<td>
<input type="text"
name="email"
size="30"
maxlength="30">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp; </td>
<td>&nbsp; </td>
<td>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</td>
</tr>
</table>
</FORM>

</BODY>
</HTML>

and here is the code for ParamterServlet.java:
package chapter2;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class ParameterServlet extends HttpServlet {

public void init(ServletConfig config) throws ServletException {
// Always pas the ServletConfig object to the super class
super.init(config);
}

// Process the HTTP Get request
public void doGet (HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException {
doPost(request, response);
}

// Process the HTTP Post request
public void doPost (HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
response.setContentType("html/text");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head>");
out.println("<title>Parameter Servlet</title>");
out.println("</head>");
out.println("<body>");

// Get an enumeration of the parameter names
Enumeration parameters = request.getParameterNames();

String param = null;

// Iterate over the parameter names,
// getting the parameters values
while(parameters.hasMoreElements()) {
param = (String)parameters.nextElement();
out.println(param + " : " + request.getParameter(param) + "<BR>");
}

out.println("</body></html>");
out.close();
}
}

Thank you and Good day!
Regards,
michael

Reply via email to