title: Retrieving record from database in Java by using select option tag
body: <p>I want to retrieve record from database by clicking on the option selected from drop down list and it as a table on the web page. But after implementing following code the web page is blank now what should I do? Any type of help will be appreciable. Here is my <code>index.jsp</code> page:</p>
  
  <pre class="lang-html prettyprint-override"><code>&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;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form name="f1" action="portal" method="POST"&gt;
              &lt;h3&gt;Name of the Book : &lt;/h3&gt;
                  &lt;select name="book" id="book"&gt;
                      &lt;option value=""&gt;Select&lt;/option&gt;
                      &lt;option value="1"&gt;The Pilgrims Progress&lt;/option&gt;
                      &lt;option value="2"&gt;Robinson Crusoe&lt;/option&gt;
                      &lt;option value="3"&gt;Gullivers Travels&lt;/option&gt;
                      &lt;option value="4"&gt;Clarissa&lt;/option&gt;
                      &lt;option value="5"&gt;Tom Jones&lt;/option&gt;
                      &lt;option value="6"&gt;The Life and Opinions of Tristram Shandy, Gentleman&lt;/option&gt;
                      &lt;option value="7"&gt;Emma&lt;/option&gt;
                      &lt;option value="8"&gt;Frankenstein&lt;/option&gt;
                      &lt;option value="9"&gt;Nightmare Abbey&lt;/option&gt;
                      &lt;option value="10"&gt;The Narrative of Arthur Gordon Pym of Nantucket&lt;/option&gt;
                      &lt;option value="11"&gt;Sybil&lt;/option&gt;
                      &lt;option value="12"&gt;Jane Eyre&lt;/option&gt;
                      &lt;option value="13"&gt;Wuthering Heights&lt;/option&gt;
                      &lt;option value="14"&gt;Vanity Fair&lt;/option&gt;
                      &lt;option value="15"&gt;David Copperfield&lt;/option&gt;
                      &lt;option value="16"&gt;The Scarlet Letter&lt;/option&gt;
                      &lt;option value="17"&gt;Moby-Dick&lt;/option&gt;
                      &lt;option value="18"&gt;Alices Adventures in Wonderland&lt;/option&gt;
                      &lt;option value="19"&gt;The Moonstone&lt;/option&gt;
                      &lt;option value="20"&gt;Little Women&lt;/option&gt;
                      &lt;option value="21"&gt;Middlemarch&lt;/option&gt;
                  &lt;/select&gt;
              &lt;input type="submit" value="submit" /&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is my servlet page for retrieving data from database</p>
  
  <pre class="lang-java prettyprint-override"><code>package com;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.ResultSetMetaData;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  public class portal extends HttpServlet {
  
      /**
       * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;
       * methods.
       *
       * @param request
       *            servlet request
       * @param response
       *            servlet response
       * @throws ServletException
       *             if a servlet-specific error occurs
       * @throws IOException
       *             if an I/O error occurs
       */
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          response.setContentType("text/html;charset=UTF-8");
          PrintWriter out = response.getWriter();
          try {
              String book = request.getParameter("book");
              Class.forName("com.mysql.jdbc.Driver");
              Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "password");
              PreparedStatement pt = conn.prepareStatement("Select * from book where Book_Name = ?");
              pt.setString(1, book);
              out.print("&lt;table width = 75%&gt;");
              out.print("&lt;center&gt;&lt;h1&gt;Welcome To The Portal&lt;/h1&gt;&lt;/center&gt;");
              ResultSet rs = pt.executeQuery();
              ResultSetMetaData rsd = rs.getMetaData();
              while (rs.next()) {
                  out.print("&lt;tr&gt;");
                  out.print("&lt;td&gt;" + rsmd.getColumnName(1) + "&lt;/td&gt;");
                  out.print("&lt;td&gt;" + rs.getString(1) + "&lt;/td&gt;&lt;/tr&gt;");
                  out.print("&lt;tr&gt;&lt;td&gt;" + rsmd.getColumnName(2) + "&lt;/td&gt;");
                  out.print("&lt;td&gt;" + rs.getString(2) + "&lt;/td&gt;&lt;/tr&gt;");
                  out.print("&lt;tr&gt;&lt;td&gt;" + rsmd.getColumnName(3) + "&lt;/td&gt;");
                  out.print("&lt;td&gt;" + rs.getString(3) + "&lt;/td&gt;&lt;/tr&gt;");
                  out.print("&lt;tr&gt;&lt;td&gt;" + rsmd.getColumnName(4) + "&lt;/td&gt;");
                  out.print("&lt;td&gt;" + rs.getString(4) + "&lt;/td&gt;&lt;/tr&gt;");
                  RequestDispatcher rd = request.getRequestDispatcher("logout.jsp");
                  rd.include(request, response);
              }
              out.println("&lt;/table&gt;");
          }
  
          catch (Exception e) {
              out.println(e);
          }
      }
  
      // &lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the
      // + sign on the left to edit the code."&gt;
      /**
       * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
       *
       * @param request
       *            servlet request
       * @param response
       *            servlet response
       * @throws ServletException
       *             if a servlet-specific error occurs
       * @throws IOException
       *             if an I/O error occurs
       */
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
       *
       * @param request
       *            servlet request
       * @param response
       *            servlet response
       * @throws ServletException
       *             if a servlet-specific error occurs
       * @throws IOException
       *             if an I/O error occurs
       */
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Returns a short description of the servlet.
       *
       * @return a String containing servlet description
       */
      @Override
      public String getServletInfo() {
          return "Short description";
      }// &lt;/editor-fold&gt;
  
  }
  </code></pre>
  
  <p>now I don't know where I miss something.      </p>