title: Can't get SQL query results to display on a JSP Page table?
body: <p>I am creating a dynamic web project using eclipse, following the MVC design. I am currently trying to get data from my sql table to display on a JSP page but it just comes back as blank. I am using JNDI datasorce for the connection which works fine. when l deploy the project to the server the table headers appear fine but with no data below.
  Here’s my Code</p>
  
  <p>JSP code</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;  
  &lt;head&gt;  
  &lt;title&gt;View All Students&lt;/title&gt;  
  &lt;/head&gt;  
  &lt;body&gt;  
  
  &lt;h1&gt;Students List&lt;/h1&gt;  
  
  &lt;table cellpadding="5" border=1&gt;  
  
  &lt;tr valign="bottom"&gt;  
  &lt;th&gt;&lt;%= request.getAttribute("Student_Id") %&gt;&lt;/th&gt;  
  &lt;th&gt;First Name&lt;/th&gt;  
  &lt;th&gt;Last Name&lt;/th&gt;
  &lt;th&gt;Week 1&lt;/th&gt; 
  &lt;th&gt;Week 2&lt;/th&gt;
  &lt;th&gt;Week 3&lt;/th&gt;
  &lt;th&gt;Week 4&lt;/th&gt;
  &lt;th&gt;Week 5&lt;/th&gt;
  &lt;th&gt;Week 6&lt;/th&gt;
  &lt;th&gt;Week 7&lt;/th&gt;
  &lt;th&gt;Week 8&lt;/th&gt;
  &lt;th&gt;Week 9&lt;/th&gt;
  &lt;th&gt;Week 10&lt;/th&gt;
  &lt;th&gt;Week 11&lt;/th&gt;
  &lt;th&gt;Week 12&lt;/th&gt;   
  &lt;/tr&gt;  
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;  
  &lt;c:forEach var="student" items="${viewAllStudents}"&gt;  
  &lt;tr valign="top"&gt;  
  &lt;td&gt;&lt;p&gt;${student.Student_Id}&lt;/td&gt;  
  &lt;td&gt;&lt;p&gt;${student.firstName}&lt;/td&gt;  
  &lt;td&gt;&lt;p&gt;${student.lastName}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week1}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week2}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week3}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week4}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week5}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week6}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week7}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week8}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week9}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week10}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week11}&lt;/td&gt;
  &lt;td&gt;&lt;p&gt;${student.Week12}&lt;/td&gt;
  &lt;/tr&gt;  
  &lt;/c:forEach&gt;  
  
  &lt;/table&gt;  
  
  &lt;/body&gt;  
  &lt;/html&gt; 
  </code></pre>
  
  <p>Servelt (Controller) Code</p>
  
  <pre><code>    package uk.ac.qub.PTStudentView;
  
      import java.io.IOException;
      import java.sql.Connection;
      import java.sql.SQLException;
      import java.util.List;
  
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.servlet.ServletConfig;
      import javax.servlet.ServletException;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import javax.sql.DataSource;
  
      import uk.ac.qub.Beans.Student;
      import uk.ac.qub.LoginController.Account;
  
  /**
   * Servlet implementation class PTStudentViewController
   */
  @WebServlet("/PTStudentViewController")
  public class PTStudentViewController extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      private DataSource ds;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public PTStudentViewController() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see Servlet#init(ServletConfig)
       */
      public void init(ServletConfig config)  throws ServletException {
          try {
              InitialContext initContext = new InitialContext();
  
              Context env = (Context) initContext.lookup("java:comp/env");
  
              ds = (DataSource) env.lookup("jdbc/testdb");
  
          } catch (NamingException e) {
              throw new ServletException();
          }
      }
  
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  
  
  
          try {
              List&lt;Student&gt; viewAllStudents = PTViewStudent.list();
              request.setAttribute("students", viewAllStudents); // Will be available as ${students} in JSP
              request.getRequestDispatcher("ViewAllStudentsPage.jsp").forward(request, response);
          } catch (SQLException e) {
              throw new ServletException("Cannot obtain products from DB", e);
          }
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
      }
  </code></pre>
  
  <p>Class for Sql statment</p>
  
  <pre><code>package uk.ac.qub.PTStudentView;
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.ArrayList;
  import java.util.List;
  
  import uk.ac.qub.Beans.Student;
  
  public class PTViewStudent {
  private static Connection conn;
  
  public PTViewStudent (Connection conn){
      this.conn = conn;
  }
  
  public static List&lt;Student&gt; list() throws SQLException{
  
      String sql = "select * from student where Student_Id = 666";
      PreparedStatement stmt = conn.prepareStatement(sql);
  
      ResultSet rs = stmt.executeQuery();
      List&lt;Student&gt; viewAllStudents = new ArrayList&lt;&gt;();
  
      while(rs.next()){
          Student student = new Student();
          student.setId(rs.getInt("Student_Id"));
          student.setFirstName(rs.getString("firstName"));
          student.setLastName(rs.getString("lastName"));
          student.setWeek1(rs.getDouble("Week1"));
          student.setWeek2(rs.getDouble("Week2"));
          student.setWeek3(rs.getDouble("Week3"));
          student.setWeek4(rs.getDouble("Week4"));
          student.setWeek5(rs.getDouble("Week5"));
          student.setWeek6(rs.getDouble("Week6"));
          student.setWeek7(rs.getDouble("Week7"));
          student.setWeek8(rs.getDouble("Week8"));
          student.setWeek9(rs.getDouble("Week9"));
          student.setWeek10(rs.getDouble("Week10"));
          student.setWeek11(rs.getDouble("Week11"));
          student.setWeek12(rs.getDouble("Week12"));
          viewAllStudents.add(student);
      }
      return viewAllStudents;
  }
  
  }
  </code></pre>
  
  <p>Thanks For any help</p>