I tried to create a filter to stop users who are not logged in from accessing certain pages. To do this, I created a filter class with the following methoddoFilter
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String url = request.getRequestURI();
boolean allowedRequest = false;
System.out.println(url);
if(urlList.contains(url)) {
allowedRequest = true;
System.out.println("in list");
}
if (!allowedRequest) {
Object o = request.getSession().getAttribute("UserInfo");
if (null == o) {
System.out.println("Hey i am in");
response.sendRedirect("/login.jsp");
}
}
chain.doFilter(req, res);
}
To allow pages that the user does not need to log in, I created the url list of arraylist in init ()
. , home.jsp dcr.jsp. home.jsp , login.jsp, dcr.jsp, , if (null == o), , . ,
,
/dcrmaintenance.jsp
Hey i am in
, null == o .
dcr.jsp , , java.lang.NullPointerException , , . - pt out, , .