Olá,
alguém pode me ajudar a resolver um probleminha. Já perdi um tempão e não consigo resolver:
Como faço o Excluir, href abaixo na lista de alunos? Não sei se está correto, segue o código em jsp.
Lista de Alunos:
<table border="1">
<tr><td>Matr</td><td>Nome</td><td>CPF</td><td>Email</td><td>Fone</td></tr>
<%
List<Aluno> aluno = AlunoDao.getAll();
if (aluno != null) {
for (Aluno a : aluno) {
%>
<tr>
<td><%=a.getMatricula()%></td>
<td><%=a.getNome()%></td>
<td><%=a.getCpfaluno()%></td>
<td><%=a.getEmail()%></td>
<td><%=a.getFone()%></td>
<td><a href='formCadAluno?matricula=<%= a.getMatricula() %>'>Alterar</a><br /></td> // (AQUI ESTÁ CORRETO?)
<td><a href='deletarAluno?matricula=<%= a.getMatricula()%>'>Excluir</a><br /></td>// (AQUI ESTÁ CORRETO?)
</tr>
<%
}
} %>
</table>
Controller - Servlet (nome arquivo: deletarAluno.java):
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String matricula = request.getParameter(“matricula”);
AlunoDao.excluir(matricula);
response.sendRedirect(“listarAlunos.jsp”);
}
Excluir (DAO):
public static boolean excluir(String matricula) {
Connection conn = MySql.getConn();
try {
conn.createStatement().execute("DELETE FROM aluno WHERE matricula = " + matricula);
return true;
}
catch (SQLException e) {
e.printStackTrace();
return false;
}
}
