[ajuda]login em jsp

2 respostas
J
Essa e minha Tela Inicial
<html>
<head>
    <title>Area Restrita</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
      <p align="center"/>
      <img src="http://4.bp.blogspot.com/-vy4EuaNfQ8A/TftT4wsHfbI/AAAAAAAAARo/7espbSSGm-c/s250/area_restrita.gif"/>
    <form id="form1" name="form1" method="post" action="-">
    <table width="200" border="0" align="center">
<tr>
    <td>Login:
    <td>
    <input type="text" name="login" id="login" />
</label>
</tr>
    <tr>
    <td>Senha:
<td>

    <input type="password" name="senha" id="senha" />
    </label>
</tr>
<tr>
<td>
<td>
    <input type="submit" name="button" id="button" value="Logar" />
    <input type="reset" name="button" id="button" value="Limpar"/>
</label>
</tr>
</table>
</form>
</body>
</html>
tela de sucesso
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Logado</title>
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>

tela de erro

<html>
<head>
    <title>Pagina de Erro</title>
</head>
<body bgcolor="white">
    Usuario ou senha inválidos!!!<a href= "index.jsp">Tente outra vez</a>.
</body>
</html>

agora preciso fazer um usuario admin e senha admin sem bd para efutar login caso nao for o admin ir para a tela de erro oq devo fazer

2 Respostas

mausexdd

Bom dia , jcquinhone

Dentro da sua Servlet
ussando o método doPost igual voce esta fazendo um exemplo simples seria assim

protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String login = request.getParameter("txtLogin"); //Este txtLogin é o nome do meu textBox la no meu JSP
		String senha = request.getParameter("txtSenha"); //mesma coisa...

	RequestDispatcher d; //Esta objeto é importante .. veja

Usuario u = new Usuario();
		u.setNome(nome);
		u.setLogin(login);

BancoUsuarios bdu = new BancoUsuarios();

		if (senha.equals(confirmaSeha)) {
			bdu.cadastrarUsuario(u);
			d = request.getRequestDispatcher("cadastroSucesso.html"); // ELE QUE ENCAMINHA PARA SUAS PAGINAS!
		} else {
			d = request.getRequestDispatcher("cadastroErro.html");
		}
		try {
			d.forward(request, response);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

Espero ter ajudado !
FernandoFranzini

Vc fez a pagina só meu querido…falta a componentes que faz a logica de autenticação…
Qual tecnologia “server-side” vc domina?
Escolha uma e manda ver…

Criado 29 de agosto de 2011
Ultima resposta 30 de ago. de 2011
Respostas 2
Participantes 3