Validação no redirecionamento
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>
Estou fazendo uma validação para email e senha. Portanto, quando o usuário inserir o e-mail e a senha corretos, ele será encaminhado para success.jsp. E se o usuário inserir detalhes incorretos, ele redirecionará a página para index.jsp junto com o erro.
Mas eu não consigo fazê-lo funcionar nas partes de detalhes erradas.
AVISO: StandardWrapperValve [com.events.ValidationServlet]: PWC1406: Servlet.service () para servlet com.events.ValidationServlet lançou uma exceção