HttpSessionListener开展同名用户剔除登录的方法
HttpSessionListener进行同名用户剔除登录的方法?link hrefcss/maincss.css relstylesheet typet
HttpSessionListener进行同名用户剔除登录的方法
?
<link href="css/maincss.css" rel="stylesheet" type="text/css">
</head>
<body>
<%?
???????? //UserInfoForm为后台定义的获取用户登录信息及保存用户相关信息的一个java bean,userSession为用户登录Action时根据需要组装的放置用户信息的一个bean对象-UserInfoForm,登录成功后被放到session里(这里的session指HttpSession,即服务端根据每个客户端链接产生的带有唯一sessionId)。
???????? UserInfoForm userInfoForm = (UserInfoForm)request.getSession().getAttribute("userSession");
???????? //System.out.println("userName="+userInfoForm.getUserName());
???????? if(userInfoForm.getUserName()==null||userInfoForm.getUserName().equals("")){//从session获取用户信息失败,用户没有登录或session已经超时,返回到登录页面
???????????? RequestDispatcher dispatcher=request.getRequestDispatcher("login.jsp");
????????? dispatcher.forward(request,response);
???????? }else{
???????????? if(!SessionListener.isLogining(userInfoForm.getUserName())){//用户没有登录或session已经超时
???????????????? RequestDispatcher dispatcher=request.getRequestDispatcher("login.jsp");
??????? dispatcher.forward(request,response);
???????????? }else{
???????????????? if(!SessionListener.isOnline(request.getSession())){//当前用户不在线,即session已经被剔除
???????????????????? RequestDispatcher dispatcher=request.getRequestDispatcher("login.jsp");
???????????????????? dispatcher.forward(request,response);
???????????????? }
???????????? }
???????? }
%>
</body>
</html:html>
3.?注意:最后别忘了在web.xml文件中配置监听器SessionListener:
????? <listener>
????????? <listener-class>com.projectsSrcPath.SessionListener</listener-class>
????? </listener>