The study of Httpsessionbindinglistener

Source: Internet
Author: User

Interface Httpsesssionbindinglistenner extends EventListener;

An introduction to the API documentation for this interface is to let the object be notified when it is bound to a session or removed from its binding. The object is HttpSessionBindingEvent notified through the object. This could be the result of a servlet programmer explicitly unbinding a property from the session (because the session is invalid or because the session timed out).

There are two methods of this interface: 1. void Valuebound (Httpsessionbindingevent event) 2. void Valueunbound (Httpsessionbindingevent event).

Httpsesssionbindinglistenner inherits from the EventListener interface, and the EventListener interface is this:

Public interface eventlistener:a tagging interface, all event listener interfaces must extend. This statement indicates that EventListener is just a token interface, similar to Cloneable,serializable, which is simply the interface used to mark the event listener. The specific use is as follows:

JavaBean implements the Httpsesssionbindinglistenner interface and implements its two methods, which call both methods of the JavaBean object when the object is not bound to the session or is notified of its binding timing from the conversation.

1 Importjavax.servlet.http.HttpSessionBindingEvent;2 ImportJavax.servlet.http.HttpSessionBindingListener;3  Public classUserImplementshttpsessionbindinglistener{4     PrivateString name;5     PrivateString pwd;6     PrivateUserList userlist=userlist.getinstance (); 7      PublicUser () {8         //TODO auto-generated Constructor stub9     }Ten      PublicUser (string name, string pwd) { One         Super(); A          This. Name =name; -          This. PWD =pwd; -     } the      PublicString GetName () { -         returnname; -     } -      Public voidsetName (String name) { +          This. Name =name; -     } +      PublicString getpwd () { A         returnpwd; at     } -      Public voidsetpwd (String pwd) { -          This. PWD =pwd; -     } - @Override -      PublicString toString () { in         return"User [name=" + name + ", pwd=" + pwd + "]"; -     } to      Public voidValuebound (httpsessionbindingevent arg0) { +         //TODO auto-generated Method Stub -          This. Userlist.adduser ( This); theSystem.out.println ( This. name+ "On the line! The current number of people online is: "+ This. Userlist.getcount ()); *     } $      Public voidValueunbound (httpsessionbindingevent arg0) {Panax Notoginseng         //TODO auto-generated Method Stub -          This. Userlist.removeuser ( This); theSystem.out.println ( This. name+ "Offline! The current number of people online is: "+ This. Userlist.getcount ()); +     } A}

Tool class:

1 Importjava.util.ArrayList;2 Importjava.util.List;3  Public classuserlist {4     Private StaticUserList userlist=Newuserlist ();5     PrivateList<user> list=NewArraylist<user>();6     Privateuserlist () {7         //TODO auto-generated Constructor stub8     }9      Public Staticuserlist getinstance () {Ten         returnuserlist; One     } A      Public voidaddUser (user user) { - list.add (user); -     } the      Public voidremoveuser (user user) { - list.remove (user); -     } -      Public intGetCount () { +         returnlist.size (); -     } +}

The above is about Httpsesssionbindinglistenner interface learning ...

The study of Httpsessionbindinglistener

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.