title: How do I display the data from a database table via EJB in JSP?
body: <p>I need to display a database table in JSP.</p>
  
  <p>I have a session bean that contains a method to display all the data found in the database.</p>
  
  <p>How do I use it in JSP?</p>
  
  <p>Code (from comment below):</p>
  
  <pre><code>@Override public List findAll() { 
     String flightQuery = "SELECT f FROM Flights f"; 
     Query q = em.createQuery(flightQuery); 
     List existing = q.getResultList(); 
  
     if (existing.isEmpty()) { 
         System.out.println("Invalid");
     }
     return existing; 
  }
  </code></pre>
  
  <p>JSP Code</p>
  
  <pre><code>&lt;c:forEach items="${flights}" var="flight"&gt; 
     &lt;tr&gt; 
     &lt;td&gt;${flight.flightid}&lt;/td&gt; 
     &lt;td&gt;&lt;c:out value="${flight.flightnumber}" /&gt;&lt;/td&gt; 
     &lt;td&gt;&lt;c:out value="${flight.datetime}" /&gt;&lt;/td&gt; 
     &lt;td&gt;&lt;c:out value = "${flight.seatsleft}"&lt;/td&gt; 
     &lt;td&gt;&lt;c:out value="${flight.id}" /&gt;&lt;/td&gt; 
     &lt;td&gt;&lt;c:out value="${flight.price}" /&gt;&lt;/td&gt; 
     &lt;td&gt;&lt;c:out value="${flight.originairport}" /&gt;&lt;/td&gt; 
     &lt;td&gt;&lt;c:out value="${flight.destinationairport}" /&gt;&lt;/td&gt;
     &lt;/tr&gt;
  &lt;/c:forEach&gt; 
  &lt;/table&gt; 
  </code></pre>
  
  <p>It is not displaying in a table.</p>