Estou melhorando um projetinho que fiz para minha faculdade e me veio a ideia de melhorar a parte do login do meu site. Quando eu realizo uma tentativa de login e digito algo errado ele irá abrir uma nova aba e mostrará a mensagem “Credencias incorretas”, porém, eu gostaria que ele exibisse uma mensagem em vermelho “H1” na mesma página do login com o nome “Credencias incorretas” ao invés de abrir uma nova guia. Alguém pode me ajudar a como fazer isso ?
Classe LoginUsuarioServlet
@WebServlet("/LoginUsuarioServlet")
public class LoginUsuarioServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String email = req.getParameter("email");
String senha = req.getParameter("senha");
AutentificarLogin autentificar = new AutentificarLogin();
Usuario usuario = new Usuario();
usuario = autentificar.Autentificar(email, senha);
if (usuario != null) {
PrintWriter printWriter = resp.getWriter();
resp.sendRedirect("Locadora.jsp");
} else {
PrintWriter printWriter = resp.getWriter();
printWriter.print("<body>");
printWriter.print("<h1>Credenciais incorretas. Verifique seu E-mail e sua senha.</h1>");
printWriter.print("<a href= 'index.jsp'>Voltar</a>");
}
}
}
Formulário JSP
<img class="img-capa" alt="Capa" src="./img/CAPA.jpg">
<div class="login">
<img class="imglogin" alt="" src="./img/logo.png">
<form action="<%=request.getContextPath()%>/LoginUsuarioServlet"
method="get">
<h5 style="color: black; font-family: sans-serif;">
E-MAIL: <input type="email" required name="email">
</h5>
<h5 style="color: black; font-family: sans-serif;">
SENHA: <input type="password" required name="senha">
</h5>
<p>
<h5 style="font-family: sans-serif;">
<a style="text-decoration: none; color: black;"
href='usuario/Usuario_Cadastrar.jsp'> É novo por aqui ?
Cadastre-se</a>
</h5>
<br> <input
style="border-radius: 5px; position: relative; left: 95px;"
type="submit" value="Entrar">
</form>
</div>
