session.getAttribute 的个小问题

boytomato boytomato 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest)arg0;
HttpServletResponse response = (HttpServletResponse)arg1;
HttpSession session = request.getSession(false);

arg2.doFilter(arg0, arg1);

if(session.getAttribute("logged-in")!=null)
{}
}




2008-5-16 12:38:58 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException

已经确认是 if(session.getAttribute("logged-in")!=null)的问题,可如何判断这个 session 为空啊。。。
...全文
评论 18
收藏 已收藏
分享
返回顶部
boytomato
Web 开发 81,108 成员 341,721 内容