在做单点登录时我们使用application来维护session时在拦截器的位置遇到这样的问题
String username = (String) session.getAttribute("username");//username是账户
ServletContext application = request.getSession().getServletContext();
System.out.println("拦截的用户名字"+username);
String session1Id = (String) application.getAttribute(username);
经过调试是在String session1Id = (String) application.getAttribute(username);
出抛出异常,经测试后发现如果传入的username
为null的时候会抛出异常,因此需要处理下为null的username
if(username==null){
username="" ;
}