import javax.servlet.http.*;
import javax.servlet.*;
import java.io.IOException;
public class MyServlet extends HttpServlet
{
public void doPost (HttpServletRequest req, HttpServletResponse res) throws IOException
{
ServletOutputStream out = res.getOutputStream();
res.setContentType("text/html");
out.println("Basic Form Processor Output ");
out.println("");
out.println("Here is your Form Data
");
//extract the form data here
String title = req.getParameter("title");
String name = req.getParameter("name");
String city = req.getParameter("city");
String country = req.getParameter("country");
String tel = req.getParameter("tel");
String age = req.getParameter("age");
// extracting data from the checkbox field
String[] interests = req.getParameterValues("interests");
//output the data into a web page
out.println("Your title is " + title);
out.println("
Your name is " + name);
out.println("
Your city is " + city);
out.println("
Your country is " + country);
out.println("
Your tel is " + tel);
out.println("
Your interests include ");
for (int i=0;i out.println("- " + interests[i]);
}
out.println("
");
out.println("
Your age is " + age);
out.println("");
}
}
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
MyServletName
MyServlet
MyServletName
*.do
JSP Unleashed, Chapter 1 - A Basic HTML Form
Please enter your information