title: Getting data from servlet and printing in jsp
body: <p>I Need Help Regarding How to Print ResultSet Which i Am Getting From Servlet in Jsp
  Here Is The Servlet Code:</p>
  
  <pre><code>import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.Statement;
  
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  public class EditRecord extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  Connection con;
  Statement stmt;
  ResultSet rs;
  DBConnection dbconn;
  String sql;
  HttpSession session;
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws       ServletException, IOException {
      doPerform(request, response);
  }
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      doPerform(request, response);
  } 
  
  private void doPerform(HttpServletRequest request,HttpServletResponse response) 
  {
  
      try {
          PrintWriter out = response.getWriter();
          System.out.println("This is EditRecord Servlet");
          session= request.getSession();
          String id =(String) session.getAttribute("id");
          System.out.println(id);
          dbconn = new DBConnection();
          con= dbconn.getConnection();
          System.out.println(con);
          sql ="select * from STUDENT_CRUD where id='"+id+"' ";
          System.out.println(sql);
          stmt = con.createStatement();
          rs = stmt.executeQuery(sql);
          System.out.println("Resultset From EditRecord Servlet  ="+rs);
          if(rs.next())
          {
              System.out.println(rs.getString(1));
              System.out.println(rs.getString(2));
              System.out.println(rs.getString(3));
              System.out.println(rs.getString(4));
              System.out.println(rs.getString(5));
          }
  
  
      } 
      catch (Exception e) 
      {
  
          e.printStackTrace();
      }
      finally
      {
  
          try 
          {
              session.setAttribute("resultset", rs);
              RequestDispatcher rd= request.getRequestDispatcher("editrecord.jsp");
              rd.forward(request, response);
              //response.sendRedirect("editrecord.jsp");
          } 
          catch (Exception e) 
          {
              System.out.println("This is finally block editrecord.jsp");
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>Then The Jsp File i write is like:</p>
  
  <pre><code>&lt;%@page import="java.sql.ResultSet"%&gt;
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  
  &lt;form name="editrecord"&gt;
  
      &lt;% ResultSet rs =(ResultSet)session.getAttribute("resultset"); 
        out.println("this is getAttribute of resultset"+rs);
  
      %&gt;
       &lt;TABLE BORDER="1"&gt;
          &lt;TR&gt;
              &lt;TH&gt;ID&lt;/TH&gt;
              &lt;TH&gt;FIRSTNAME&lt;/TH&gt;
              &lt;TH&gt;LASTNAME&lt;/TH&gt;
              &lt;TH&gt;SUBJECT&lt;/TH&gt;
              &lt;TH&gt;YEARS&lt;/TH&gt;
          &lt;/TR&gt;
          &lt;% while(rs.next()){ %&gt;
          &lt;tr&gt;
   &lt;!--               &lt;td&gt;ID&lt;/td&gt; --&gt;
              &lt;td&gt; &lt;input type="text" name="id" value="&lt;%=rs.getString(1) %&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
  &lt;!--                &lt;td&gt;FirstName&lt;/td&gt; --&gt;
              &lt;td&gt;&lt;input type="text" name="firstname" value="&lt;%=rs.getString(2) %&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
  &lt;!--                &lt;td&gt;LastName&lt;/td&gt; --&gt;
              &lt;td&gt;&lt;input type="text" name="lastname" value="&lt;%=rs.getString(3) %&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
  &lt;!--                &lt;td&gt;Subject&lt;/td&gt; --&gt;
              &lt;td&gt;&lt;input type="text" name="subject" value="&lt;%=rs.getString(4) %&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
  &lt;!--                &lt;td&gt;years&lt;/td&gt; --&gt;
              &lt;td&gt;&lt;input type="text" name="years" value="&lt;%=rs.getString(5) %&gt;"&gt;&lt;/td&gt;
  
          &lt;/tr&gt;           
          &lt;% } %&gt;
      &lt;/TABLE&gt;    
  
  
  
   &lt;/form&gt;    
  </code></pre>
  
  <p>The result i am getting is :</p>
  
  <pre><code>enter code here
  </code></pre>
  
  <p>this is getAttribute of resultsetoracle.jdbc.driver.OracleResultSetImpl@5e79fc 
      ID FIRSTNAME LASTNAME SUBJECT YEARS </p>
  
  <p>The ResultSetData i am  Getting inside EditServet but not in editrecord.jsp Why?
  pls help..........</p>