1

我有简单的过滤器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会话属性enterAttr为 false 或 null 时。但我总是得到 NullPointerException

java.lang.NullPointerException
com.project.reservation.web.filter.SimpleFilter.doFilter(SimpleFilter.java:48)

怎么了?o我认为当对象为空时它不会继续。但它仍然抛出这个异常。

4

0 回答 0