Principal principal = ((HttpServletRequest) req).getUserPrincipal(); if (principal == null) { req.setAttribute("errorMessage", "Please Login"); req.getRequestDispatcher("/login.jsp").forward(req, res); } else { chain.doFilter(req, res); }