In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "how to implement the Servlet listener", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement the Servlet listener.
1) concept:
1) listen for creation events, destruction events, and changes in properties of domain objects such as ServletContext, HttpSession, and ServletRequest. 2) when the state of the domain object changes, the server automatically calls the method in the listener object.
2) listeners:
1) ServletContext2) HttpSession3) ServletRequest
3) listening content:
Listen for events such as creation and destruction of objects and changes in object properties
4) Classification:
Divided by listening objects: 1) ServletContext object listeners: implement ServletContextListener, ServletContextAttributeListener interface applications: as timers, load global attribute objects, create global database connections, load cache information, etc. 2) HttpSession object listeners: implement HttpSessionListener, Configure session timeout in HttpSessionAttributeListener API web.xml (in minutes): 10 applications: count the number of people online, record access logs, etc. 3) ServletRequest object listeners: implement ServletRequestListener, ServletRequestAttributeListener interface application: reading request parameters Record access history is divided by listening events: 1) listeners for creating and destroying events of domain objects: implement ServletContextListener, HttpSessionListener, ServletRequestListener interfaces 2) listeners for adding events and deleting events of attributes in domain objects: implement ServletContextAttributeListener, HttpSessionAttributeListener, and ServletRequestAttributeListener interfaces. 3) listeners for state change events bound to an object in HttpSeesion (create a normal JavaBean): implementation interfaces and methods: HttpSessionBindingListener interfaces (valueBound and valueUnbound methods), Object state in the HttpSessionActivationListener interface (sessionWillPassivate and sessionDidActivate methods) HttpSession: bind: save bean to the session object through the setAttribute () method unbind: unbind (serialize): unbind the session by the removeAttribue () method Like persistence to the storage device activation (deserialization): recover session objects from the storage device session passivation mechanism: 1) temporarily serialize session objects rarely used by the server to system files or databases When in use, it is deserialized into memory, and the whole process is automatically completed by the server. 2) the passivation mechanism of session is managed by SessionManager. To create a normal JavaBean binding and unbinding, you need to implement the HttpSessionBindingListener interface 3) JavaBean must implement the Serializable interface.
5) implement:
Example of complete class name of web.xml: org.springframework.web.context.ContextLoaderListener org.springframework.security.web.session.HttpSessionEventPublisher org.springframework.web.context.request.RequestContextListener 60 start order of listeners: start according to the configuration order of web.xml
6) Note:
Loading order: listeners > filters > Servlet so far, I believe you have a deeper understanding of "how to implement Servlet listeners". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.