1, you do not have to understand all listener API, not many, a total of 8. However, you need to know what you can monitor so that you can look it up when you need it.
2, about session and cookie. See Javaweb Learning Summary (12)--session by aloof Wolf
3, Httpsessionbindinglistener
This is a very useful listener, why is it useful? Because it can help us to synchronize the actual object and database information. For example:
Packagecom.example;Importjavax.servlet.http.HttpSessionBindingEvent;ImportJavax.servlet.http.HttpSessionBindingListener; Public classDogImplementsHttpsessionbindinglistener {PrivateString breed; PublicDog (String breed) { This. Breed =breed; } PublicString getbreed () {returnbreed; } @Override Public voidValuebound (httpsessionbindingevent httpsessionbindingevent) {//If I was added to a session, execute the code .} @Override Public voidValueunbound (httpsessionbindingevent httpsessionbindingevent) {//If I remove from a session, execute this code }}
Our actual data is usually stored in the database, so we generally need to use database information to populate the fields of the dog object, but the question is, how do we keep the database record and the dog object's information synchronized? Also, when do they synchronize?
Obviously, the moment we "want to use objects" and "no Objects" (between which objects can change ) is the moment we synchronize, how do we know when an object is used or not? This requires a listener,--httpsessionbindinglistener.
"Head first Servlets and JSP" Note 8: Listener