bom gente, olá a todos. estou tentando fazer com que um formulário dispare a execução de um servlet. Tenho vários outros formulários que fazem a mesma coisa, mas eles não dão erro só esse que vou mostrar para vocês.
Servlet:
[code]package controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;
import model.Aluno;
import model.Funcionario;
import model.Professor;
import model.Usuario;
import model.dao.AlunoDAO;
import model.dao.FuncionarioDAO;
import model.dao.ProfessorDAO;
public class ContCadastroServlet extends HttpServlet {
protected void contCadastro(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
//obtem as informações inseridas no formulário
String matricula = request.getParameter("matricula");
String nome = request.getParameter("nome");
String cpfs = request.getParameter("cpf");
String senha = request.getParameter("senha");
String outraSenha = request.getParameter("outraSenha");
String news = request.getParameter("newsletter");
//converção para inteiro
int cpf = Integer.parseInt(cpfs);
int newsletter = Integer.parseInt(news);
//verifica se as senhas inseridas pelo usuário são iguais
if ( senha.equals(outraSenha) )
{
//termina o cadastro do aluno
if (matricula.equals("ALU"))
{
//executa o segundo cadastro
Aluno alu = AlunoDAO.ContCadAluno(matricula, nome, cpf, senha, newsletter);
//verifica se o cadastro foi realizado com sucesso ou não
if ( alu != null )
{
JOptionPane.showMessageDialog( null, "Cadastro realizado com sucesso!" );
}else
{
JOptionPane.showMessageDialog( null, "Não foi possível realizar o seu cadastro, por favor tente mais tarde!" );
response.sendRedirect("index.jsp");
}
//termina o cadastro do professor
}else if ( matricula.equals("PRO") )
{
Professor prof = ProfessorDAO.contCadProfessor(matricula, nome, cpf, senha, newsletter);
//verifica se o cadastro foi realizado com sucesso ou não
if ( prof != null )
{
JOptionPane.showMessageDialog( null, "Cadastro realizado com sucesso!" );
}else
{
JOptionPane.showMessageDialog( null, "Não foi possível realizar o seu cadastro, por favor tente mais tarde!" );
response.sendRedirect("index.jsp");
}
//termina o cadastro do funcionario
}else if ( matricula.equals( "FUN" ) )
{
Funcionario func = FuncionarioDAO.contCadFuncionario(matricula, nome, cpf, senha, newsletter);
//verifica se o cadastro foi realizado com sucesso ou não
if ( func != null )
{
JOptionPane.showMessageDialog( null, "Cadastro realizado com sucesso!" );
response.sendRedirect("indexAdmin.jsp");
}else
{
JOptionPane.showMessageDialog( null, "Não foi possível realizar o seu cadastro, por favor tente mais tarde!" );
response.sendRedirect("index.jsp");
}
}
}else
{
JOptionPane.showMessageDialog(null, "As senhas inseridas não são iguais.");
response.sendRedirect("cadastroAluno.jsp");
}
}catch ( Exception e )
{
JOptionPane.showMessageDialog(null, "Erro no cadastro, por favor tente mais tarde!");
e.printStackTrace();
}finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
contCadastro(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
contCadastro(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
[/code]
formulário:
[code]
<input type="text" class="inp-form" name="nome"/></td>
<td></td>
</tr>
<tr>
<th valign="top">MatrÃcula:</th>
<td>
<input type="text" class="inp-form" name="matricula" /></td>
<td></td>
</tr>
<tr>
<th valign="top">CPF:</th>
<td>
<input type="text" class="inp-form" name="cpf" /></td>
<td></td>
</tr>
<th valign="top">Redefinir senha:</th>
<td>
<input type="text" class="inp-form-error" name="senha"/></td>
<td>
<div class="error-left"></div>
<div class="error-inner">MÃn. 8 Máx. 20 Caracteres</div>
<td></td>
</tr>
<tr>
<th valign="top">Repetir senha:</th>
<td>
<input type="text" class="inp-form" name="outraSenha"/></td>
<td></td>
</tr>
<tr>
<th valign="top">Newsletter:</th>
<td>
<p>
<!-- ESCOLHER CATEGORIA -->
<input name="Receber atualizações no email cadastrado" type="checkbox" value="atualizacoes" checked />
</p>
<p>Receber atualizações para o email cadastrado </p></td>
<td></td>
</tr>
<tr>
<th> </th>
<td valign="top">
<!-- BOTAO ENVIAR -->
<input type="submit" value="" class="form-avancar"/>
<!-- BOTAO RESETAR -->
<input type="reset" value="" class="form-reset" />
</form>[/code]
Na minha IDE (netbeans), não dispara exception nenhuma, mas o tomcat fala que o ContCadastroServlet (servlet mostrado), não está avaliado.
segue ai o print do erro:
Espero que você possam me ajudar, desde já mito grato!