Validación en Redirigir
validation.java
try
{
conn = dsEvent.getConnection();
String userCheck = "select * from customer";
stmt = conn.createStatement();
rs = stmt.executeQuery(userCheck);
while(rs.next()){
if((email.equals(rs.getString("email")))&&(password.equals(rs.getString("password"))))
{
RequestDispatcher rd = req.getRequestDispatcher("/success.jsp");
rd.forward(req,res);
}
else
{
req.getSession().setAttribute("error", "The email or password you entered is incorrect. Please try again");
res.sendRedirect(this.getServletContext().getContextPath() + "/index.jsp");
}
}
} catch (SQLException ex) {
System.err.println(ex);
}
}
index.jsp
<body>
<h2>System</h2>
<p style ="color:red"><%=session.getAttribute("error")!=null ? "":session.getAttribute("error") %></p>
<form method ="post" action="validation">
Please Login: <br/>
Email: <input type="email" name="email" required/><br/>
Password: <input type="password" name="password" required/><br/>
<input type ="submit" value="Login"/>
</form>
</body>
Estoy haciendo una validación para correo electrónico y contraseña. Entonces, cuando el usuario ingresa el correo electrónico y la contraseña correctos, se reenviará a success.jsp. Y si el usuario ingresa detalles incorrectos, redirigirá la página a index.jsp junto con el error.
Pero parece que no puedo hacer que funcione en las partes de detalles incorrectas. Me dio
ADVERTENCIA: StandardWrapperValve [com.events.ValidationServlet]: PWC1406: Servlet.service () para servlet com.events.ValidationServlet arrojó una excepción