Boa tarde pessoal,
Segui as dicas enviadas pelo pessoal no tópico: http://www.guj.com.br/java/80718-como-mostrar-uma-mensagem-no-jsp- mas não obtive sucesso.
Será que alguém poderia analisar meu código e dizer o que tem de errado?
minha Servlet:
package Servlet;
import DAO.LoginDAO;
import Object.LoginObject;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
*
* @author murilo
*/
public class LoginServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException, ClassNotFoundException {
response.setContentType("text/html;charset=UTF-8");
// Variaveis usuario (pega da JSP), senha (pega da JSP) e pagina(definida conforme permissão)
String usuario = request.getParameter("usuario");
String senha = request.getParameter("senha");
String pagina;
// verifica se o usuário existe no banco de dados e retorna o objeto login se existir e null se nao existir
LoginObject login = LoginDAO.login(usuario, senha);
if (login != null){
//Atualiza a Data do ultimo Login
LoginDAO.updateUltimoAcesso(login);
// Cria a sessão com o objeto
HttpSession sessao = request.getSession();
sessao.setAttribute("login", login);
// Página a ser redirencionada
pagina = "Sistema/mural.jsp";
} else {
// Mensagem de erro para a JSP
request.setAttribute("mensagem","Usuário ou Senha Inválidos!");
// Página a ser redirencionada
pagina = "index.jsp";
}
//para teste sem o banco de dados
/*if ("1".equals(usuario)){
HttpSession sessao = request.getSession();
sessao.setAttribute("login", usuario);
sessao.setAttribute("permissao", "Administrador");
pagina = "Sistema/menu.jsp";
} else if ("0".equals(usuario)){
HttpSession sessao = request.getSession();
sessao.setAttribute("login", usuario);
sessao.setAttribute("permissao", "Usuario");
pagina = "Sistema/menu.jsp";
} else {
HttpSession sessao = request.getSession();
sessao.setAttribute("login", usuario);
sessao.setAttribute("permissao", "Negada");
pagina = "index.jsp?login=erro";
}*/
response.sendRedirect(pagina);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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" />
<title>SGC - Sistema de Integração Condominial</title>
<style rel="stylesheet" type="text/css"/>
html, body { padding: 0; margin: 0;}
p {padding: 0; margin: 0;}
#geral {width: 100%; height: 100%;}
#fundo {width: 100%; height: 200px; background-image: url(Imagens/fundologin.png); position: absolute; top: 50%; margin-top: -100px;}
#logoform {width: 455px; height: 200px; margin: 0 auto;}
#logo {float:left; margin-top: 35px;}
#form {float:right; margin-top: 40px; font-family: Tahoma; font-size: 10px;}
#campo {border: 1px solid #CCC; height: 20px; width: 150px; margin-bottom: 5px; }
#botao {height: 25px; width: 150px; background: #FFF; margin-top: 8px; font-family:Tahoma;}
#erro {color: #FF0000;}
#erro1 {color: #FF0000;}
#pop {display: none; position:absolute;top:50%;left:50%;margin-left:-150px;margin-top:-102px;width:300px;height:201px;border:1px solid #d0d0d0; background: #fff;}
#pop {font-family: Tahoma; font-size: 10px;}
#pop p {padding: 8px ; margin: 0px;}
</style>
</head>
<body>
<div id="geral">
<div id="fundo">
<div id="logoform">
<img id="logo" src="Imagens/sic248x130.png"/>
<form id="form" method="get" action="Login">
<p>Usuário</p>
<p><input id="campo" name="usuario" type="text" /></p>
<p>Senha</p>
<p><input id="campo" name="senha" type="password" /></p>
<p><input id="botao" name="entrar" type="submit" value="ENTRAR"/></p>
<p><a href="#" id="senha" onclick="document.getElementById('pop').style.display='block'">Esqueceu a senha?</a><p>
<p>${mensagem}</p>
</form>
</div>
</div>
<div id="pop">
<form name="form" method="post" id="form1">
<p><label>Usuário: <input id="usuario" name="usuario" type="text" size="40" maxlength="40" /></label></p>
<p><label>E-mail: <input id="email" name="email" type="text" size="40" maxlength="40" /></label></p>
<p><input name="Enviar" type="submit" value="Recuperar" formaction="LoginEnviarEmail" />
<input name="Fechar" type="submit" value="Fechar" onclick="document.getElementById('pop').style.display='none'" /></p>
</form>
</div>
</div>
</body>
</html>
Obrigado por enquanto!