title: Output from servlet to JSP
body: <p>I am passing parameters from JSP page <em>calendar.jsp</em> to a servlet <em>connect.java</em>.
  In the Java class I am passing a query from a database. It retrievs data fine but I need it to print the result back to the JSP page.</p>
  
  <p>I tried the following code but with an error at <code>out.println()</code>.</p>
  
  <pre><code>@WebServlet("/calendar")
  public class Connect extends HttpServlet {
  
      @Override
      protected void service(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
          String fromDate = request.getParameter("fromDate");
          String toDate = request.getParameter("toDate");
          System.out.println("fromDate----&gt;"+fromDate);
          System.out.println("toDate----&gt;"+toDate);
          String query = "SELECT action_time,user_action,user_ip,user_id FROM ksdi.login_detail where (action_time, action_time) OVERLAPS (DATE '"
                      + fromDate+ "',DATE '"+ toDate+ "'+ integer '1')" +
                      " order by action_time desc";
  
          Connection conn = null;
          PreparedStatement statement = null;
          ResultSet resultSet = null;
          try {
              conn = ConnectionUtil.getConnection();
              statement = conn.prepareStatement(query);
              resultSet = statement.executeQuery();
  
              if (resultSet.next()) {
                  while (resultSet.next()) {
                      String action_time=resultSet.getString("action_time");
                      String user_action=resultSet.getString("user_action");
                      String user_ip=resultSet.getString("user_ip");
                      String user_id=resultSet.getString("user_id");
                      System.out.println((action_time) + " " + (user_action) + " "+(user_ip) + " "+(user_id) + " ");
  
                      response.setContentType("text/html");  
                      PrintWriter out = response.getWriter();  
                      out.println("action time"+((ResultSet) request).getString("action_time")+"&lt;br /&gt;");  
                      RequestDispatcher view = request.getRequestDispatcher("calendar.jsp");  
                      view.forward(request,response);         
                  }
              } else {
                  System.out.println("not found");
              }
          } catch (SQLException e) {
              throw new ServletException("DB interaction failed", e);
          } catch (Exception e) {
              e.printStackTrace();
          } finally {
              if (resultSet != null) try { resultSet.close(); } catch (SQLException ignore) {}
              if (statement != null) try { statement.close(); } catch (SQLException ignore) {}
              if (conn != null) try { conn.close(); } catch (SQLException ignore) {}
          }
      }
  
  }
  </code></pre>
  
  <p><br>
  Here is my JSP file:</p>
  
  <pre><code>&lt;%@ page import="java.sql.*" %&gt;
  &lt;%  String path = request.getContextPath();%&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  
      &lt;script src="&lt;%=path%&gt;/js/calendar.js"&gt;&lt;/script&gt;
      &lt;link href="&lt;%=path %&gt;/css/calendar.css" rel="stylesheet"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="calendar"&gt;
              &lt;div class="container"&gt;
              From:&lt;input  name="fromDate" type="text" class="calendarSelectDate" /&gt;
              To: &lt;input   name="toDate"   type="text" class="calendarSelectDate" /&gt;
              &lt;input type="submit" name="b1" value="Go"&gt;
          &lt;/div&gt;          
  &lt;div id="calendarDiv"&gt;&lt;/div&gt;
  
  
  &lt;/form&gt; 
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>