title: retrieving data from database using jsp
body: <p>I want to retrieve data from database using jsp and display it on jsp. I tried with jsp and servlet and it is working but when I want to do with only jsp its giving this error.</p>
  
  <p>retrieve.jsp:</p>
  
  <pre><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;h4&gt;Enter Employee ID and the dates&lt;/h4&gt;
      &lt;form name="retrieve form" action="display.jsp" method="POST"&gt;
          &lt;table border="0"&gt;
  
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Employee ID&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="Emp_id" required="required"/&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;From Date:&lt;/td&gt;
                      &lt;td&gt;&lt;input type="date" name="From" value="yyyy/MM/dd" required="required"/&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;To Date:&lt;/td&gt;
                      &lt;td&gt;&lt;input type="date" name="To" value="yyyy/MM/dd" required="required"/&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
          &lt;input type="reset" value="Clear" name="clear" /&gt;
          &lt;input type="submit" value="Submit" name="submit" /&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Display.jsp:</p>
  
  <pre><code>&lt;%@page import="java.sql.*"%&gt;
  &lt;%@page import="com.eis.bean.ConnectionProvider" %&gt;
  &lt;%@page import="com.eis.bean.Provider" %&gt;
  &lt;%@page import="java.util.Date"%&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;JSP Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;%! 
          public class RD{
  
  
          PreparedStatement ps = null; 
          ResultSet rs = null;
          public RD(){
             try{ 
          Connection conn=ConnectionProvider.getConn();  
          ps = conn.prepareStatement("SELECT * FROM timsheetdb.logintable WHERE Emp_id=? and LoginDate BETWEEN ? AND ?; ");  
  
             }
             catch(Exception e){
                 e.printStackTrace();
             }
          }
  
          public ResultSet getRD(String Emp_id, String from, String to){
              try{
                  ps.setString(1,Emp_id);
                  ps.setString(2,from);
                  ps.setString(3,to);
  
              }
              catch(Exception e){
                 e.printStackTrace();
             }   
              return rs;
          }
          }
  %&gt;
  &lt;% String employeeid= new String();
   String date1= new String();
   String date2= new String();
  
   if(request.getParameter("Emp_id")!=null){
       employeeid= request.getParameter("Emp_id");
   }
  
   if(request.getParameter("from")!=null){
       date1= request.getParameter("from");
   }
  
   if(request.getParameter("to")!=null){
       date2= request.getParameter("to");
   }
  
   RD rd= new RD();
   ResultSet table= rd.getRD(employeeid,date1,date2);
      %&gt;
     &lt;table border="0"&gt;
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Emp_id&lt;/td&gt;
                      &lt;td&gt;Login Date&lt;/td&gt;
                      &lt;td&gt;Login Time&lt;/td&gt;
                      &lt;td&gt;Logout Time&lt;/td&gt;
                      &lt;td&gt;Task&lt;/td&gt;
                      &lt;td&gt;Total&lt;/td&gt;
                      &lt;td&gt;Overtime&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;% while (table.next()){ 
                 %&gt; &lt;tr&gt;
                      &lt;td&gt;&lt;%=table.getString("Emp_id") %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%=table.getString("LoginDate") %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%=table.getString("LoginTime") %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%=table.getString("LogoutTime") %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%=table.getString("task") %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%=table.getString("Total") %&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%=table.getString("Overtime") %&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;% } %&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>below is the error which I got:</p>
  
  <pre><code>HTTP Status 500 - An exception occurred processing JSP page /display.jsp at line 80
  
  type Exception report
  
  message An exception occurred processing JSP page /display.jsp at line 80
  
  description The server encountered an internal error that prevented it from  fulfilling this request.
  
  exception
  
  org.apache.jasper.JasperException: An exception occurred processing JSP page     /display.jsp at line 80
  
  77:                         &lt;td&gt;Total&lt;/td&gt;
  78:                         &lt;td&gt;Overtime&lt;/td&gt;
  79:                     &lt;/tr&gt;
  80:                     &lt;% while (rs.next()){ 
  81:                    %&gt; &lt;tr&gt;
  82:                         &lt;td&gt;&lt;%=rs.getString("Emp_id") %&gt;&lt;/td&gt;
  83:                         &lt;td&gt;&lt;%=rs.getString("LoginDate") %&gt;&lt;/td&gt;
  Stacktrace:
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  root cause
  
  java.lang.NullPointerException
  org.apache.jsp.display_jsp._jspService(display_jsp.java:178)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  note The full stack trace of the root cause is available in the Apache      Tomcat/8.0.26 logs.
  </code></pre>
  
  <p>please let me know how I can I resolve this.</p>