Hi,
I kind of new to this....
I am using JBuilder 7 to do this project...
I am displaying four textboxes and a submit button on the browser...
When i click the submit, i want to call the POST method in my class and print out the Parameter Name and Parameter Value....
I don't know if i am doing it right or not, but if someone can see how can i get the Parameter name and Value when i submit the button...
I am attaching the code...
Any help would be greatly appreciated...
============================================================
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class Servlet1 extends HttpServlet {
static final private
String CONTENT_TYPE = "text/html";
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println(createSearchForm());
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse res)
throws IOException, ServletException
{
String xParameterName = null;
String xParameterValue = null;
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
xParameterName = (String) e.nextElement();
if((xParameterName.compareTo("firstName")==0)){
xParameterValue = request.getParameterValues(xParameterName)[0];
PrintWriter out = res.getWriter();
System.out.println(xParameterName);
System.out.println(xParameterValue);
}
}
}
//Clean up resources
public void destroy() {
}
public String createSearchForm(){
StringBuffer sb = new StringBuffer();
sb.append("<form action=\"Servlet1\" method=POST >");
sb.append("\n");
sb.append("<p align=\"center\">");
sb.append("\n");
sb.append("First Name:");
sb.append("\n");
sb.append("<input name=\"firstnameTextfield\" type=\"text\" size=\"20\" maxlength=\"20\">");
sb.append("\n");
sb.append("Last Name:");
sb.append("\n");
sb.append("<input name=\"textfield\" type=\"text\" size=\"20\" maxlength=\"20\">");
sb.append("\n");
sb.append("</p>");
sb.append("\n");
sb.append("\n");
sb.append("<br>");
sb.append("\n");
sb.append("<br>");
sb.append("\n");
sb.append("<p align=\"center\">");
sb.append("\n");
sb.append("Policy Number:");
sb.append("\n");
sb.append("<input name=\"textfield2\" type=\"text\" size=\"20\" maxlength=\"20\">");
sb.append("\n");
sb.append("SSN:");
sb.append("\n");
sb.append("<input name=\"textfield3\" type=\"text\" size=\"20\" maxlength=\"9\">");
sb.append("\n");
sb.append("</p>");
sb.append("\n");
sb.append("<br>");
sb.append("\n");
sb.append("<p align=\"center\">");
sb.append("\n");
sb.append("<input type=\"submit\" >");
sb.append("\n");
sb.append("</p>");
sb.append("\n");
sb.append("</form>");
return sb.toString();
}
}