CRUD em jsp e servlet - excluir e alterar não funcionam

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;
}
}

Sua dificuldade, no método excluir?
utilize executeUpdate(); ao invés de execute();

Não deu, mesmo usando executeUpdate(); ou executeQuery();

Dá o seguinte ERRO:

HTTP Status 404 - /Avaliacao3/deletarAluno

type Status report

message /Avaliacao3/deletarAluno

description The requested resource (/Avaliacao3/deletarAluno) is not available.

Apache Tomcat/6.0.32

[quote=lorenzo]Não deu, mesmo usando executeUpdate(); ou executeQuery();

Dá o seguinte ERRO:

HTTP Status 404 - /Avaliacao3/deletarAluno

type Status report

message /Avaliacao3/deletarAluno

description The requested resource (/Avaliacao3/deletarAluno) is not available.

Apache Tomcat/6.0.32[/quote]

Por favor, utilize a tag code para postar teus códigos. Uma pergunta, ao menos a requisição está chegando no teu Servlet? Me deu a impressão que não. Se não, deve ter tido algum log mais detalhado, poste-o.

Ok, obrigado pelo toque!
Acho que nem está chegando no Servlet.
O clique no botão Excluir deve estar errado, fiz assim:

<td><a href='deletarAluno?matricula=<%= a.getMatricula()%>'>Excluir</a><br /></td>

Segue o código do Servlet (deletarAluno.java):

[code]package br.senai.sc.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.senai.sc.bd.dao.AlunoDao;

public class deletarAluno extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String matricula = request.getParameter("matricula");
	AlunoDao.excluir(matricula);
	response.sendRedirect("listarAlunos.jsp");
}

}[/code]

E como está o seu web.xml ?
Veja a URL completa que ele monta com o href nesse formato e confere com a que está configurada no seu web.xml.

Estava diferente.
Agora alterei o nome do Servlet no xml:

<servlet> <description> </description> <display-name>excluirAluno</display-name> <servlet-name>excluirAluno</servlet-name> <servlet-class> br.senai.sc.controller.excluirAluno</servlet-class> </servlet> <servlet-mapping> <servlet-name>excluirAluno</servlet-name> <url-pattern>/excluirAluno</url-pattern> </servlet-mapping> <servlet-mapping>
href:

<td><a href='excluirAluno?matricula=<%= a.getMatricula()%>'>Excluir</a><br /></td>

Endereço completo do href:
http://localhost:8080/Avaliacao3/excluirAluno?matricula=2 (sendo que esta url peguei do aluno com matrículo = 2)

Agora, executando não dá erro, mas ele não exclui do BD e a página fica em branco após clicar no Excluir.

Não consegue realizar um debug no teu sistema ?
De duas uma:

1 - Não encontrou ninguém com esse valor, por isso não exclui
2 - Tem alguma exception sendo lançada “para baixo do tapete”

Tem outras, mas acredito que seja as principais. Se não consegue debugar, coloque bastante log, assim, consegue identificar com clareza os passos.

Cara, não sei debugar, sou bem iniciante em java. Mas vou tentar aprender.
Mas enquanto isso, como se coloca log?

[quote=lorenzo]Cara, não sei debugar, sou bem iniciante em java. Mas vou tentar aprender.
Mas enquanto isso, como se coloca log?[/quote]

Você pode usar biblioteca, como o log4j.
Porém, o mais simples e rápido, é simplesmente usar o bom e velho System.out.println. Adicione ele em cada classe e método que ele deve passar, desde o Servlet até o seu DAO. Nas exceções, use o printStacktrace() delas para imprimir a exceção, caso ocorra, posteriormente, tu te preocupa em fazer um tratamento mais adequado.

Abraços.

Tenta botar alguns System.out.println(); no seu código para saber até aonde ele esta indo.

Exemplo: coloca um System.out.println(“Chegou na Servlet”); no começo da Servlet, outro bem antes de você invocar o metodo de excluir System.out.println(“Vai invocar a exclusao”); outro logo após chamar o metodo System.out.println(“Chamou o metodo de exclusão”); e por ai vai. Assim que eu faço :smiley: