Olá galera.
Se possível gostaria de um auxilio, estou desenvolvendo uma aplicação utilizando os padrões DAO e MVC
Preciso implementar o login e guardar os dados do usuario numa sessão e estou com muitas duvidas…
Meu FormJSP:
<html >
<head>
<title>Untitled Document</title>
<style type="text/css">
<!--
.style2 {font-size: 18px}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="get" action="Controller">
<p> </p>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3"><div align="center"><span class="style2">Autenticação de Usuário</span></div></td>
</tr>
<tr>
<td width="51"> </td>
<td width="198"> </td>
<td width="51"> </td>
</tr>
<tr>
<td>Login:</td>
<td colspan="2"><label>
<input type="text" name="txtLogin" id="txtLogin" />
</label></td>
</tr>
<tr>
<td>Tipo:</td>
<td colspan="2"><label>
<select name="selectTipo" id="selectTipo">
<option value="0">Candidato</option>
<option value="1">Empresa</option>
</select>
</label></td>
</tr>
<tr>
<td>Senha:</td>
<td colspan="2"><label>
<input type="password" name="txtSenha" id="txtSenha" />
</label></td>
</tr>
<tr>
<td> </td>
<td colspan="2"><input name="btnLogin" type="submit" id="btnLogin" value="Login" /></td>
</tr>
</table>
<label></label>
<p> </p>
<p> </p>
</form>
</body>
</html>
Meu Servlet - Controller:
import java.io.IOException;
import java.util.HashMap;
import com.projeto.sistemaVagas.comandos.ComandoLoginForm;
@SuppressWarnings("serial")
public class Controller extends HttpServlet {
private HashMap<String, ComandoAbstrato> comandos;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
executaControlador(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
executaControlador(req, resp);
}
@SuppressWarnings("unchecked")
private void executaControlador(HttpServletRequest req,
HttpServletResponse resp) {
iniciarComandos();
// recuperando ovalor do parametro "do"
String parametroDo = req.getParameter("do");
try {
// recuperando um objeto de comando a ser executado
ComandoAbstrato comando = comandos.get(parametroDo);
// se o comando (objeto) de "do" for nulo, lança um erro
if (comando == null)
throw new Exception();
//if (comandoId == null)
// throw new Exception();
// executando uma regra de negócio
Object resultado = comando.execute(req.getParameterMap());
req.setAttribute("resultado", resultado);
// definindo a pagina de saída
RequestDispatcher dispatcher = req.getRequestDispatcher(comando.getPaginaSucesso());
dispatcher.forward(req, resp);
} catch (Exception e) {
// imprimindo o erro no console
e.printStackTrace();
}
}
private void iniciarComandos() {
// instanciando o hashmap (tabela) de comandos
comandos = new HashMap<String, ComandoAbstrato>();
// EXIBE JANELA DE LOGIN
ComandoAbstrato comandoLoginForm = new ComandoLoginForm();
comandoLoginForm.setPaginaSucesso("/paginas/janelaLoginForm.jsp");
}
}
Comando que exibe a Janela Login
public class ComandoLoginForm extends ComandoAbstrato{
public Object execute(Map<String, String[]> parametros) throws Exception {
System.out.println("ComandoLoginForm");
return null;
}
}
Preciso verificar se o usuario esta logado cada vez que ele acesse o Servlet( Controller) caso não esteja redirecionar para a pagina de login

