rbrmendes
2014-10-22 13:41:26 UTC
Good Morning !
I'm trying to display data from a list in the browser , but the information is not displayed . I tried in several ways but the information does not appear.
I'll post my code :
Code:
public class AlunoDAO extends DAO {
public List<Aluno> listar() {
List<Aluno> lista = new ArrayList<>();
try {
Connection conexao = getConexao();
Statement stm = conexao.createStatement();
ResultSet rs = stm.executeQuery("Select * from aluno");
while (rs.next()) {
Aluno aluno = new Aluno();
aluno.setMatricula(rs.getLong("matricula"));
aluno.setNome(rs.getString("nome"));
lista.add(aluno);
}
stm.close();
conexao.close();
} catch (Exception e) {
e.printStackTrace();
}
return lista;
}
}
Code:
String destino = "sucesso.jsp";
List<Aluno> lista = new ArrayList<>();
Aluno aluno = new Aluno();
AlunoDAO dao = new AlunoDAO();
aluno.setMatricula(Long.parseLong(request.getParameter("matricula")));
aluno.setNome(request.getParameter("nome"));
lista = dao.listar();
request.setAttribute("listaAluno", lista);
RequestDispatcher rd = request.getRequestDispatcher(destino);
rd.forward(request, response);
Code:
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Code:
<table border="1">
<tr>
<td>Matricula</td>
<td>Nome</td>
</tr>
<c:forEach var="aluno" items="${listaAluno}">
<tr>
<td>${aluno.matricula}</td>
<td>${aluno.nome}</td>
</tr>
</c:forEach>
</table>
Thanks
I'm trying to display data from a list in the browser , but the information is not displayed . I tried in several ways but the information does not appear.
I'll post my code :
Code:
public class AlunoDAO extends DAO {
public List<Aluno> listar() {
List<Aluno> lista = new ArrayList<>();
try {
Connection conexao = getConexao();
Statement stm = conexao.createStatement();
ResultSet rs = stm.executeQuery("Select * from aluno");
while (rs.next()) {
Aluno aluno = new Aluno();
aluno.setMatricula(rs.getLong("matricula"));
aluno.setNome(rs.getString("nome"));
lista.add(aluno);
}
stm.close();
conexao.close();
} catch (Exception e) {
e.printStackTrace();
}
return lista;
}
}
Code:
String destino = "sucesso.jsp";
List<Aluno> lista = new ArrayList<>();
Aluno aluno = new Aluno();
AlunoDAO dao = new AlunoDAO();
aluno.setMatricula(Long.parseLong(request.getParameter("matricula")));
aluno.setNome(request.getParameter("nome"));
lista = dao.listar();
request.setAttribute("listaAluno", lista);
RequestDispatcher rd = request.getRequestDispatcher(destino);
rd.forward(request, response);
Code:
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Code:
<table border="1">
<tr>
<td>Matricula</td>
<td>Nome</td>
</tr>
<c:forEach var="aluno" items="${listaAluno}">
<tr>
<td>${aluno.matricula}</td>
<td>${aluno.nome}</td>
</tr>
</c:forEach>
</table>
Thanks