title: Fetch, process and display the result on the same page
body: <p>I have a jsp page containing a form where a user fills in some value. Now i pass these values into a servlet  which processes it and retieves a related set of data. Now, i am able to retrieve the data in the servlet page, but am not able to display it on the same jsp page at which i fetched the request.  </p>
  
  <hr>
  
  <p><strong>I do not want to use java code inside jsp. I wish to do the same using servlets only. I do not want to do something like this</strong></p>
  
  <hr>
  
  <pre><code>&lt;% if(rollno==null)
        // then display the form
     else 
        // process the request on the jsp page itself  
  %&gt;
  </code></pre>
  
  <hr>
  
  <p>I want to process all my reults in a servlet file and then dispaly the result on the jsp page <strong>by passing data from servlet to jsp</strong>. I am posting my code below :</p>
  
  <hr>
  
  <pre><code>&lt;form id="form" method="post" action="searchServlet"&gt;
  Student Roll No :&lt;br&gt;&lt;input type="text" value="" name="rollno"&gt;&lt;br&gt;&lt;br&gt;
  &lt;input type="submit" value="SHOW DETAILS" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try {
              String rollno=request.getParameter("rollno");
              ResultSet rs=null;
  
              Class.forName("com.mysql.jdbc.Driver");  
              String url="jdbc:mysql://localhost/schooldatabase";
              Connection con = DriverManager.getConnection(url,"root","passwd");
  
              Statement st= (Statement) con.createStatement();
              String strquery="SELECT name,regno FROM `schooldatabase`.`student_info` WHERE rollno="+ rollno+ ";";
  
              if(!con.isClosed()) {
                  rs=st.executeQuery(strquery);
  
                  while(rs.next())
                  {
                      out.println(rs.getString("name"));
                      out.println(rs.getString("regno"));
                  }
              }
  
              else
              {    // The connection is closed 
              }
            }           
  
              catch(Exception e)
              {
                  out.println(e);
              }
  
               finally {            
                 out.close();
              }
  }
  </code></pre>