Servlet Form Processor CheckBox : Form « Servlet « Java Tutorial

import javax.servlet.http.*;
import javax.servlet.*;

public class MyServlet extends HttpServlet
  public void doPost (HttpServletRequest req, HttpServletResponse res) throws IOException
    ServletOutputStream out = res.getOutputStream();
    out.println("<html><head><title>Basic Form Processor Output</title></head>");
    out.println("<h1>Here is your Form Data</h1>");
    //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("<br>Your name is "  + name);
    out.println("<br>Your city is "  + city);
    out.println("<br>Your country is "  + country);
    out.println("<br>Your tel is "  + tel);
    out.println("<br>Your interests include<ul> ");
    for (int i=0;i<interests.length; i++) {
    out.println("<li>" + interests[i]);
  out.println("<br>Your age is "  + age);
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"



<title>JSP Unleashed, Chapter 1 - A Basic HTML Form</title>
<h1>Please enter your information</h1>
<form method="POST" action="">
  Title: <select size="1" name="title">
  Name: <input type="text" name="name" size="20"><br>
  City: <input type="text" name="city" size="20"><br>
  Country: <input type="text" name="country" size="20"><br>
  Telephone: <input type="text" name="tel" size="20">
  <P>Please inform us of your interests:<br>
  <input type="checkbox" name="interests" value="Sport">Sport<br>
  <input type="checkbox" name="interests" value="Music">Music<br>
  <input type="checkbox" name="interests" value="Reading">Reading<br>
  <input type="checkbox" name="interests" value="TV and Film">TV and Film</p>
  <P>Your age
  <input type="radio" name="age" value="25orless" checked>Less than 25
  <input type="radio" name="age" value="26to40">26-40
  <input type="radio" name="age" value="41to65">41-65
  <input type="radio" name="age" value="over65">Over 65</p>
  <P><input type="submit" value="Submit"></p>
  Download: 1,068 k)

25.3.1.Servlet Post Form Data to Self Servlet
25.3.2.Get Form Text Field as a Servlet parameter
25.3.3.Servlet Form Processor CheckBox
25.3.4.Servlet Based GuestBook