0
I tried to list database information on a page JSP by means of the tag <c:forEach>
but I’m not getting any return value.
Bookoid:
@Override
public List<Livro> consultar() throws SQLException{
List<Livro> livros = new ArrayList<Livro>();
try {
String sql = "SELECT * FROM liros WHERE st_ativo=1";
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery(sql);
while(result.next()) {
Livro li = new Livro();
li.setTitulo(result.getString("titulo"));
li.setPaginas(result.getInt("paginas"));
li.setAutor(result.getString("autor"));
li.setEditora(result.getString("editora"));
livros.add(li);
}
} catch(SQLException e) {
e.printStackTrace();
}
return livros;
}
Listbook.jsp:
<tr>
<th>Titulo</th>
<th>Páginas</th>
<th>Autor</th>
<th>Editora</th>
<th>Editar</th>
<th>Deletar</th>
</tr>
</thead>
<tbody>
<c:forEach var="li" items="$(livros)">
<tr>
<td><c:out value="$(li.titulo)" /></td>
<td><c:out value="$(li.paginas)"/></td>
<td><c:out value="$(li.autor)"/></td>
<td><c:out value="$(li.editora)"/></td>
<td><a href="Servlet?action=editar&id" >Editar</a></td>
<td><a href="Servlet?action=deletar&id" >Deletar</a></td>
</tr>
</c:forEach>
</tbody>
Note: I use the driver jstl1.2
What could be wrong with my code?
Utilize
${...}
instead of$(...)
. That is, use keys, not parentheses.– Victor Stafusa