title: Display data in jsp page
body: <p>I need to manually display data from database in jsp page. But it wont display.</p>
  
  <p>My entity:</p>
  
  <pre><code>@Entity
  @NamedQuery(name="Contact.getAll", query="SELECT c FROM Contact c") 
  public class Contact implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @Id
  private String login;
  private String name;
  private String surname;
  
  getters/setters/equals/hashcode
  </code></pre>
  
  <p>Bean to manage jsp:</p>
  
  <pre><code>public class DisplayDataBean {
  
  private EntityManagerFactory emf = Persistence.createEntityManagerFactory("ContactsPU");
  private EntityManager em = emf.createEntityManager();
  private List&lt;Contact&gt; contacts = em.createNamedQuery("Contact.getAll", Contact.class).getResultList();
  
  public List&lt;Contact&gt; getContacts() {
      return contacts;
  }
  }
  </code></pre>
  
  <p>And jsp page fragment:</p>
  
  <pre><code>        &lt;c:forEach var="contact" items="${DisplayDataBean.contacts}"&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;c:out value="${contact.login}"/&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;c:out value="${contact.name}"/&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;c:out value="${contact.surname}"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/c:forEach&gt;
  </code></pre>
  
  <p>Can you please tell what can be wrong in here? Thanks in advance.</p>
  
  <p>Also when i work with </p>
  
  <pre><code>&lt;sql:query var="contacts" dataSource="jdbc/contactapplication"&gt;
      SELECT * FROM contact;
  &lt;/sql:query&gt;
  </code></pre>
  
  <p>everything is fine.</p>
  
  <p>Problem was that i didnt declare DisplayDataBean. 
  Solution is to add tag in jsp page:</p>
  
  <pre><code>&lt;jsp:useBean id="displayBean" class="web.DisplayDataBean"/&gt;
  </code></pre>