Listener based listener life cycle (detailed explanation)

1、 Listener lifecycle

Listener is one of the three major components of the web. It is a servlet listener, which is used to listen to requests and the operation of the server.

Listeners are divided into: (they are all interface classes, and corresponding methods must be implemented)

1. Life cycle listener (3)

2. Attribute change listeners (3)

Except for different parameters, the method names of the above listener interfaces are the same. Listen for attribute changes of application, session and request objects respectively.

3. Specified class attribute change listener in session (2)

2、 Test example

1. Life cycle monitoring:

ServletContentAttribute_ Listener. java

The other two listeners are similar and are not posted repeatedly.

On the web Configuration in XML

Operation results:

2. Attribute listening:

ServletContentAttribute_ Listener. java

The other two listeners are similar and are not redundant. Next, test with JSP pages

listenerDemo. jsp

The results are as follows:

Note: one of the problems encountered is that when starting tomcat, servletcontextlistener listens and executes twice, and finally deletes the server Manually configure the context in XML so that it will not be loaded twice.

The above article based on the listener listener life cycle (detailed explanation) is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>