title: Servlets with JavaBeans
body: <p>I have a set of three servlets, each one of them has a form with radio buttons that passes its values to the next servlet. What I am trying to do is to make a JavaBean class to use with the servlets and keep the state of them and the choices of the radio buttons while going from one servlet to another. Could anyone suggest some sample code for the JavaBean please?</p>
  
  <p>Here is some of the first servlet code:</p>
  
  <p>(The other two servlets have same code for other questions)</p>
  
  <pre><code>protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try {
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;Servlet 1&lt;/title&gt;");            
          out.println("&lt;/head&gt;");
          out.println("&lt;form  id=\"form1\" action = \"Servlet2\" method = \"POST\"&gt;");
          out.println("&lt;input type = \"radio\" name = \"Q1\" value = \"Answer 1\"&gt; Answer 1 &lt;br /&gt;\n" +
                      "&lt;input type = \"radio\" name = \"Q1\" value = \"Answer 2\"&gt; Answer 2 &lt;br /&gt;\n" +
                      "&lt;input type = \"radio\" name = \"Q1\" value = \"Answer 3\"&gt; Answer 3 &lt;br /&gt; &lt;br /&gt;");
  
          out.println("&lt;input type = \"radio\" name = \"Q2\" value = \"Answer 1\"&gt; Answer 1 &lt;br /&gt;\n" +
                      "&lt;input type = \"radio\" name = \"Q2\" value = \"Answer 2\"&gt; Answer 2 &lt;br /&gt;\n" +
                      "&lt;input type = \"radio\" name = \"Q2\" value = \"Answer 3\"&gt; Answer 3 &lt;br /&gt; &lt;br /&gt;");
  
          out.println("&lt;input type = \"radio\" name = \"Q3\" value = \"Answer 1\"&gt; Answer 1 &lt;br /&gt;\n" +
                      "&lt;input type = \"radio\" name = \"Q3\" value = \"Answer 2\"&gt; Answer 2 &lt;br /&gt;\n" +
                      "&lt;input type = \"radio\" name = \"Q3\" value = \"Answer 3\"&gt; Answer 3 &lt;br /&gt; &lt;br /&gt;");
          out.println("&lt;input type = \"submit\" value = \"Next\"&gt;");
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
      } finally {            
          out.close();
      }
  }
  </code></pre>
  
  <p>Thank you.</p>