Boa tarde galera, segue abaixo o codigo para verificação,
durante o código vou estar comentando e explicando o q está acontecendo
index.jsp// bom acho q aqui num tem segredo, só um formulário mandando os dados
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/styleLogin.css" />
<link rel="shortcut icon" href="favion.ico" />
<title>Login do Sistema</title>
</head>
<body>
<div id="box">
<div id="content">
<div id="header">
<div id="header_topo">
<img />
<p>Bem vindo a Comunidade Bahá'í do Brasil!</p>
</div><!--fecha div topo-->
</div><!--fecha div header-->
<div id="corpo">
<div id="corpo_txt">
<p>SIGAB -<span>ADMINISTRAÇÃO</span></p>
</div><!--fecha div txt-->
<div id="corpo_form">
<form method="post" action="EfetuarLogin.do" >
<label>
<span>Login:</span>
<input type="text" name="login" />
</label>
<label>
<span>Senha:</span>
<input type="password" name="senha" />
</label>
<input type="submit" name="entrar" value="Entrar" />
</form>
</div><!--fecha div form-->
</div><!--fecha div corpo-->
<div id="footer">
<p>"...Hoje todos os horizontes do mundo estão iluminados com a luz da unidade
fomos criados para levar avante uma civilização em constante evolução..."</p>
</div><!--fecha div footer-->
</div><!--fecha div content-->
</div><!--fecha div box-->
</body>
</html>
Meu servlet: EfetuarLogin.java
package controllers;
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.servlet.http.HttpSession;
import modelo.Usuario;
import modelo.UsuarioDAO;
public class EfetuarLogin extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
try {
String login, senha;
login = request.getParameter("login");
senha = request.getParameter("senha");
Usuario usuario = new Usuario();
usuario.setLogin(login);
usuario.setSenha(senha);
// bom até aki eu testei se ele estava recebendo os valores do formulario, aparentemente tudo OK
UsuarioDAO usuarioDB = new UsuarioDAO();//o erro começa apartir daki
//se eu comentar todo o resto abaixo e deixar a linha de cima da erro na minha execução.
usuarioDB.conectar();
usuario = usuarioDB.logar(usuario);
session.setAttribute("usuario", usuario);
if (usuario.getId() > 0) {
response.sendRedirect("areaAdmin.jsp");
} else {
out.print("<script language='javascript' type='text/javascript'>");
out.print(" alert('Usuário ou senha inválidos!');");
out.print(" window.location = 'controle.do?acao=login';");
out.print("</script>");
}
usuarioDB.desconectar();
} catch (Exception e) {
out.print(e);
}
}
// <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 {
processRequest(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 {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Minha classe DAO: UsuarioDAO
package modelo;
import Cryptography.Cryptography;
import Cryptography.CryptographySHA512;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
public class UsuarioDAO extends DataBaseDAO {
public UsuarioDAO() throws Exception {
}
public Usuario logar(Usuario usuario) throws Exception {
Statement stm;
ResultSet rs;
stm = conn.createStatement();
String pass;
String sql = "SELECT * FROM usuario WHERE login='" + usuario.getLogin() + "'";
rs = stm.executeQuery(sql);
Cryptography cryptography;
cryptography = new CryptographySHA512();
pass = cryptography.encrypt(usuario.getSenha());
if (rs.next()) {
if (rs.getString("senha").equals(pass)) {
usuario.setId(rs.getInt("id"));
usuario.setPerfilId(rs.getInt("perfil_id"));
usuario.setAl(rs.getInt("assembleia_local_id"));
usuario.setNome(rs.getString("nome"));
usuario.setLogin(rs.getString("login"));
usuario.setSenha(rs.getString("senha"));
return usuario;
}
}
return usuario;
}
meu javaBean: Usuario
package modelo;
public class Usuario {
private int id;
private int perfilId;
private int al;
private String nome;
private String login;
private String senha;
private Perfil perfil;
private AssembleiaLocal assembleiaLocal;
public Usuario() {
}
public Usuario(int id, int perfilId, int al, String nome, String login, String senha) {
this.id = id;
this.perfilId = perfilId;
this.al = al;
this.nome = nome;
this.login = login;
this.senha = senha;
}
public Usuario(int id, int perfilId, int al, String nome, String login, String senha, Perfil perfil) {
this.id = id;
this.perfilId = perfilId;
this.al = al;
this.nome = nome;
this.login = login;
this.senha = senha;
this.perfil = perfil;
}
public Usuario(int id, int perfilId, int al, String nome, String login, String senha, Perfil perfil, AssembleiaLocal assembleiaLocal) {
this.id = id;
this.perfilId = perfilId;
this.al = al;
this.nome = nome;
this.login = login;
this.senha = senha;
this.perfil = perfil;
this.assembleiaLocal = assembleiaLocal;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPerfilId() {
return perfilId;
}
public void setPerfilId(int perfilId) {
this.perfilId = perfilId;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public Perfil getPerfil() {
return perfil;
}
public void setPerfil(Perfil perfil) {
this.perfil = perfil;
}
public int getAl() {
return al;
}
public void setAl(int al) {
this.al = al;
}
public AssembleiaLocal getAssembleiaLocal() {
return assembleiaLocal;
}
public void setAssembleiaLocal(AssembleiaLocal assembleiaLocal) {
this.assembleiaLocal = assembleiaLocal;
}
}
Erro na minha execução
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
java.lang.NoClassDefFoundError: Cryptography/Cryptography
controllers.EfetuarLogin.processRequest(EfetuarLogin.java:31)
controllers.EfetuarLogin.doGet(EfetuarLogin.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
java.lang.ClassNotFoundException: Cryptography.Cryptography
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
controllers.EfetuarLogin.processRequest(EfetuarLogin.java:31)
controllers.EfetuarLogin.doGet(EfetuarLogin.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.11 logs.
