Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Servlet session listener

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

HttpSessionListener- creation and destruction

/ / @ WebListener servlet3.0 supports annotations public class HttpSessionListenerDemo implements HttpSessionListener {@ Override public void sessionCreated (HttpSessionEvent httpSessionEvent) {HttpSession session = httpSessionEvent.getSession (); ServletContext servletContext = session.getServletContext (); / / undo} @ Override public void sessionDestroyed (HttpSessionEvent httpSessionEvent) {/ / undo}}

Stunning and activation of HttpSessionActivationListener-

/ / @ WebListener servlet3.0 supports annotations public class HttpSessionActivationListenerDemo implements HttpSessionActivationListener {@ Override public void sessionWillPassivate (HttpSessionEvent httpSessionEvent) {} @ Override public void sessionDidActivate (HttpSessionEvent httpSessionEvent) {}}

HttpSessionAttributeListener- attribute value change

/ / @ WebListener servlet3.0 supports annotations public class HttpSessionAttributeListenerDemo implements HttpSessionAttributeListener {@ Override public void attributeAdded (HttpSessionBindingEvent httpSessionBindingEvent) {} @ Override public void attributeRemoved (HttpSessionBindingEvent httpSessionBindingEvent) {} @ Override public void attributeReplaced (HttpSessionBindingEvent httpSessionBindingEvent) {}}

Delete or increase the value of the HttpSessionBindingListener- attribute

/ / @ WebListener servlet3.0 supports annotations public class HttpSessionBindingListenerDemo implements HttpSessionBindingListener {@ Override public void valueBound (HttpSessionBindingEvent httpSessionBindingEvent) {} @ Override public void valueUnbound (HttpSessionBindingEvent httpSessionBindingEvent) {}}

Design architecture

The design pattern of the listener is the observer pattern.

Event source: HttpSession

Events: subclasses of EventObject, such as HttpSessionEvent and HttpSessionBindingEvent

Event listener: a subclass of EventListener.

The observed is the servlet container. The observer is our listener. Usually an actual observer is introduced into a self-implemented listener to handle events.

Note: the loading order of web.xml is: [Context-Param]-> [Listener]-> [Filter]-> [Servlet], and the order of actual program calls between the same type is based on the order of the corresponding Mapping.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report