"Head first Servlets and JSP" Note 8: Listener

Source: Internet
Author: User

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

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.