【发布时间】:2020-10-06 00:13:01
【问题描述】:
我正在尝试从我的数据库中返回一个列表,但没有 JSTL 并通过这种方式(通过在 servlet 本身中添加一些 html。这是为了我的学校任务)。这是我的代码:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
Connection conexao = (Connection) new ConexaoFactory().getConnection();
Cliente cliente = new Cliente();
PreparedStatement estrutura = conexao
.prepareStatement("SELECT * FROM TB_MOVTIN_CLIENTE");
ResultSet resultadoDados = estrutura.executeQuery();
while(resultadoDados.next()) {
cliente.setId(resultadoDados.getInt("ID_CLIENTE"));
cliente.setNome(resultadoDados.getString("NOME"));
request.setAttribute("message",
"<h1>Retorno da seleção</h1>"
+ "<table border=1> "
+ "<tr> "
+ "<td>Identificação</td>"
+ "<td>Nome</td> "
+ "</tr>"
+ "<tr> "
+ "<td>" + cliente.getId() + "</td>"
+ "<td>" + cliente.getNome() + "</td>"
+ " </tr> </table>");
}
resultadoDados.close();
estrutura.close();
} catch (SQLException e) {
System.out.print("Erro: ");
e.printStackTrace();
}
RequestDispatcher dispatcher = request.getRequestDispatcher("selecionaCliente.jsp");
dispatcher.forward(request, response);
}
【问题讨论】:
标签: sql list jsp servlets oracle-sqldeveloper