The project has a login page with two fields one email and another one that is your password! I have a javaweb application and in the deployment descriptor I have some declared error pages, which are related to the errors made by the users, with these error pages I forward them to custom pages informing the respective problem! These two are famous:
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/ErroPaginaNaoEncontrada.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/ErroLogin.jsp</location>
</error-page>
The first, 404, page not found is ok.
The second, 500, login error has a small defect, I do not know if it is a mistake of mine, when the user puts his wrong email and the password is right, the application is all right! As he entered his incorrect email the error is picked up by the application and the client is forwarded to a page saying that he has put the wrong email! But if it puts the correct email and the wrong password the error is not captured by the application, I do not know what to do. What status code should I place to capture this exact password error? or what is the most viable solution? I've tried some of the line 400 up to 500, but nothing! Here is my Login servlet:
public class Login extends HttpServlet {
private UsuarioDAOInterface usuarioDAO = DAOFactory.createFactory(NomeBanco.DAO_BD).criarUsuarioDAO();
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String email = request.getParameter("email");
String senha = request.getParameter("senha");
UsuarioBean usuario = new UsuarioBean();
usuario = usuarioDAO.selecionarPorEmail(email);
HttpSession session = request.getSession();
session.setAttribute("usuario", usuario);
if (usuario.getEmail().equals(email) && usuario.getSenha().equals(senha)) {
RequestDispatcher dispatcher
= request.getRequestDispatcher("Home.jsp");
dispatcher.forward(request, response);
}
}
}