title: Dynamically display data from DB based on selection from checkbox in jsp
body: <p><strong>How to retrieve data in textbox by selecting option in check box?</strong></p>
  
  <p>Full Requirement Description:</p>
  
  <p>1) Select the multiple option in checkbox.
     For ex: Select Multiple names of checkbox.</p>
  
  <p>2) Click the submit button.</p>
  
  <p>2) In the next page data of other column should be displayed.
     For ex: All the Email-id should be displayed in textbox based on 'Names' selection in previous page</p>
  
  <p>Requirement: Simple code Using JSP and Mysql </p>
  
  <p>**</p>
  
  <blockquote>
    <p>Form1:</p>
  
  <pre><code>   1)It contains Checkbox: User selects the check box and clicks on submit button. (Moves to next Form i.e Form2 - Check the next set of code below)
  </code></pre>
  </blockquote>
  
  <p>**</p>
  
  <pre><code>    &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%&gt;
  
  &lt;%-- 
      Document   : TestAllocMainPage
      Created on : Dec 7, 2015, 6:38:37 PM
      Author     : zanxzanz
  --%&gt;
  
  &lt;%@page import="java.sql.ResultSet"%&gt;
  &lt;%@ page import="java.sql.*" %&gt; 
  &lt;%ResultSet modelSet = null;%&gt; 
  
  
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Test Alloc&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
         &lt;FORM method="POST" ACTION="NextForm.jsp"&gt;
  
             &lt;%
              try {
                  Class.forName("com.mysql.jdbc.Driver").newInstance();
                  Connection connection
                          = DriverManager.getConnection("jdbc:mysql://localhost/test_management", "root", "admin");
  
  
                  Statement statement1 = connection.createStatement();
                  modelSet = statement1.executeQuery("select * from manage_model");
                  %&gt;
  
  
  &lt;center&gt;
  Select(s): &lt;br&gt;&lt;br&gt;
  &lt;table&gt;
  &lt;tr&gt;
      &lt;td&gt;Select Model:&lt;/td&gt;
      &lt;td&gt;&lt;select name="model" id="tb1"&gt; 
                          &lt;%
                          while (modelSet.next()) {%&gt; 
                          &lt;option&gt;&lt;%=modelSet.getString(3)%&gt;&lt;/option&gt; 
                          &lt;% } %&gt; 
                      &lt;/select&gt;&lt;/td&gt;
  
  &lt;/table&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;table
  &lt;tr&gt;   
  
      &lt;td&gt; 
          &lt;input TYPE=checkbox name=member value =Name1&gt;
      &lt;/td&gt;    
      &lt;td&gt;    
          Tester1 
      &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
      &lt;td&gt; 
          &lt;input TYPE=checkbox name=member VALUE=Name2&gt;
      &lt;/td&gt;    
      &lt;td&gt;    
          Tester2
      &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
      &lt;td&gt; 
          &lt;input TYPE=checkbox name=member VALUE=Name3&gt;
      &lt;/td&gt;    
  
      &lt;td&gt;    
          Tester3
      &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
      &lt;td&gt; 
          &lt;input TYPE=checkbox name=member VALUE=Name4&gt;
      &lt;/td&gt;    
  
      &lt;td&gt;    
          Tester4
      &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
      &lt;td&gt; 
          &lt;input TYPE=checkbox name=member VALUE=Name5&gt;
      &lt;/td&gt;    
  
      &lt;td&gt;    
          Tester5
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;br&gt; &lt;INPUT TYPE=submit name=submit Value="Submit"&gt;
  &lt;/center&gt;
                      &lt;%
          //**Should I input the codes here?** 
              } catch (Exception e) {
                  out.println("wrong entry" + e);
              }
          %&gt; 
  
  &lt;/FORM&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>**</p>
  
  <blockquote>
    <p>Form2:</p>
  
  <pre><code>   1)Selected Names(checkbox) will be displayed in textbox
     2)In 'mail' textbox email-id should be retrieved from mysql based on the 'Names' selected.         
  </code></pre>
  </blockquote>
  
  <p>**</p>
  
  <pre><code>    &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%&gt;
  
  &lt;%-- 
      Document   : TestAllocProceedMain
      Created on : Dec 15, 2015, 10:37:04 AM
      Author     : zanxzanz
  --%&gt;
  
  &lt;%@page import="java.sql.ResultSet"%&gt;
  &lt;%@ page import="java.sql.*" %&gt; 
  &lt;%ResultSet mailSet = null;%&gt; 
  
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;TAP&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;%! String[] members; %&gt;
          &lt;%! String models; %&gt;
          &lt;%! String mail; %&gt;
      &lt;center&gt;Allocation Details: &lt;br&gt;
  
          &lt;%
  
              String a = request.getParameter("member1");
  
              try {
                  Class.forName("com.mysql.jdbc.Driver").newInstance();
                  Connection connection
                          = DriverManager.getConnection("jdbc:mysql://localhost/test_management", "root", "admin");
                  Statement statement1 = connection.createStatement();
  
                  mailSet = statement1.executeQuery("select Email_Id from team_member where Emp_Name ='Name1'");
  
                  %&gt;
          &lt;table&gt;
  &lt;% 
     members = request.getParameterValues("member");
     models = request.getParameter("model");
  
  
     if (members != null) 
     {
        for (int i = 0; i &lt; members.length; i++) 
        {
           //out.println ("&lt;b&gt; Tester"+i+ ": &lt;b&gt;");
           %&gt;
           &lt;input type="text" name="test" value="&lt;%=models%&gt;" /&gt;
           &lt;input type="text" name="test" value="&lt;%=members[i]%&gt;"/&gt;
      //**Email**
      &lt;input type="text" name="mail" value="&lt;%=mail%&gt;" /&gt;
           &lt;br&gt;&lt;br&gt;
      &lt;%
        }
  
     }
     else out.println ("&lt;b&gt;none&lt;b&gt;");
  %&gt;
  &lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;%
  
              } catch (Exception e) {
                  out.println("wrong entry" + e);
              }
          %&gt; 
  
  &lt;/center&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>