The only reason why your code is doing this is because your LoginModel
servlet is not being called (BTW, have you debugged it to check?).
The NullPointerException
happens because you're trying to cast a null reference to a boolean
(a safe-check would resolve this, but not the call itself).
See one example, which is working properly:
Servlet 1:
@WebServlet(urlPatterns = "/serv")
public class Serv extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("serv2");
dispatcher.include(request, response);
if (request.getAttribute("Successful") != null
&& (boolean) request.getAttribute("Successful")) {
System.out.println("Success!");
} else {
System.out.println("No success!");
}
}
}
Servlet 2:
@WebServlet(urlPatterns = "/serv2")
public class Serv2 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setAttribute("Successful", true);
}
}
Final result:
Success!