扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共19页)
public void valueBound(HttpSessionBindingEvent event) public void valueUnbound(HttpSessionBindingEvent event) |
public class HttpSessionBinding implements javax.servlet.http.HttpSessionBindingListener { ServletContext application = null; public HttpSessionBinding(ServletContext application) { super(); if (application ==null) throw new IllegalArgumentException("Null application is not accept."); this.application = application; } public void valueBound(javax.servlet.http.HttpSessionBindingEvent e) { Vector activeSessions = (Vector) application.getAttribute("activeSessions"); if (activeSessions == null) { activeSessions = new Vector(); } JDBCUser sessionUser = (JDBCUser)e.getSession().getAttribute("user"); if (sessionUser != null) { activeSessions.add(e.getSession()); } application.setAttribute("activeSessions",activeSessions); } public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent e) { JDBCUser sessionUser = (JDBCUser)e.getSession().getAttribute("user"); if (sessionUser == null) { Vector activeSessions = (Vector) application.getAttribute("activeSessions"); if (activeSessions != null) { activeSessions.remove(e.getSession().getId()); application.setAttribute("activeSessions",activeSessions); } } } } |
public void login() throws ACLException,SQLException,IOException { /* get JDBC User Class */ if (user != null) { logout(); } { // if session time out, or user didn't login, save the target url temporary. JDBCUserFactory uf = new JDBCUserFactory(); if ( (this.request.getParameter("userID")==null) || (this.request.getParameter("password")==null) ) { throw new ACLException("Please input a valid userName and password."); } JDBCUser user = (JDBCUser) uf.UserLogin( this.request.getParameter("userID"), this.request.getParameter("password") ); user.touchLoginTime(); this.session.setAttribute("user",user); this.session.setAttribute("BindingNotify",new HttpSessionBinding(application)); } } |
public void logout() throws SQLException,ACLException { if (this.user == null && this.session.getAttribute("user")==null) { return; } Vector activeSessions = (Vector) this.application.getAttribute("activeSessions"); if (activeSessions != null) { activeSessions.remove(this.session); application.setAttribute("activeSessions",activeSessions); } java.util.Enumeration e = this.session.getAttributeNames(); while (e.hasMoreElements()) { String s = (String)e.nextElement(); this.session.removeAttribute(s); } this.user.touchLogoutTime(); this.user = null; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者