Call DAO methods foreach jstl

0

I'm starting my studies in jsp and I came across the following situation: I want to use the forEach of jstl c: foreach and want to use a list that is returned by my DAO method.

<body>
<jsp:useBean id="dao" class="teste.ContatoDAO"/>
<table>
    <tr>
        <th>Nome</th>
        <th>Email</th>
        <th>Endereco</th>
    </tr>
     <c:forEach var="contato" items="${dao.findAllContatos}">
        <tr>
            <td>${contato.nome}</td>
            <td>${contato.endereco}</td>
            <td>${contato.email}</td>
        </tr>
    </c:forEach>
</table>

Where this $ {dao.findAllContacts} is my DAO method that returns a list of contact objects. However, jsp thinks that findAllContacts is a property when in fact it is a method. How do you get around this problem? Thank you in advance.

    
asked by anonymous 08.11.2017 / 22:30

1 answer

1

Hello! As suggested by Andrew, use dao.findAllContacts ().

Expression language only takes getter methods without the need to use parentheses. In other methods, its use becomes necessary.

Look for the Java-to-Web handout made available in PDF by Caelum. There, you will find a more detailed explanation.

    
17.11.2017 / 23:44