我有简单的过滤器SimpleFilter
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) arg0;
HttpServletResponse response = (HttpServletResponse) arg1;
HttpSession session = request.getSession();
Object o = null;
o = session.getAttribute("enterAttr");
if (o == null) {
response.sendRedirect("/reservation/main.jsp");
return;
}
boolean bool = (boolean) o;
if (bool == true)
arg2.doFilter(arg0, arg1);
else
response.sendRedirect("/reservation/main.jsp");
}
当会话属性main.jsp
为false或null时,我想将用户重定向到enterAttr
。
但我总是得到NullPointerException
java.lang.NullPointerException
com.project.reservation.web.filter.SimpleFilter.doFilter(SimpleFilter.java:48)
有什么问题?我认为当对象o
为空时它不会继续。但它仍然引发了这个例外。