JSP e Servlet

1 resposta
J

Boa tarde Amigos!

Tenho uma page chamada cadastro.jsp

tenho um servelt onde é cadastrado, alterado e excluido. o Nome da servlet é BancoDeDados

dentro da Servelt BancoDeDados tenho

public void Cadastrar(){

//codigo

}
public void Alterar(){

//codigo

}

public void Excluir(){

//codigo

}

alguem sabe como faço para quando a pessoa clica no botao cadastrar la na jsp ele acessa a Cadastrar na servet?

1 Resposta

O

Se entendi direito, tenta assim oh!

public class SeuServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
 {

	        private static final String CADASTRAR = "cadastrar";
		private static final String ALTERAR = "alterar";
		private static final String EXCLUIR = "excluir";
....
....
...
 ...
...
               protected void doGet(HttpServletRequest request, HttpServletResponse response) throws        ServletException, IOException {

		processarRequisicao(request, response);
	}


protected void processarRequisicao(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String tarefa = request.getParameter("tarefa");

    	if (tarefa.equals(CADASTRAR))
    		Cadastrar(request,response)

    	if (tarefa.equals(BUSCAR))
    	            Alterar(request,response)

    	if (tarefa.equals(EXCLUIR))
    		Excluir(request,response)


	}

No meu caso aqui eu uso um html, ai no html tem que ser + ou - assim!

<a href ="endereco completodo Servlet?tarefa=cadastrar"> Cadastro de novo Usuário</a><br>
<a href ="endereco do Servlet?tarefa=alterar"> alterar </a><br>
<a href = "endereco do Servlet?tarefa="excluir"> Excluir </a>

Espero ter ajudado! 8)

Criado 28 de janeiro de 2008
Ultima resposta 28 de jan. de 2008
Respostas 1
Participantes 2