Javaweb Learning Listener Monitoring

Source: Internet
Author: User

OneListenerListener

Java EE includes 13-door specifications in the course of the main learning servlet technology and JSP technology

where The servlet specification consists of three technical points: Servlet Listener Filter

1. What is a listener?

A listener is a component that listens for changes in the state of an object

Concepts related to listeners:

Event Source: The object being monitored -----Three domain objects request session ServletContext

Listener: Listen for event source Object The change in the state of the event source object will trigger the listener ----6+2

Register listener: Binds the listener to the event source

response behavior: When the listener hears the state of the event source changes The functional code involved ----the programmer to write code

2. What are the listeners?

First Dimension: According to the object being monitored: ServletRequest domain httpsession domain servletcontext domain

Second dimension: Listen to the content of: listen to the creation and destruction of the domain object The properties of the listener domain object are changed

1. Listener for creation and destruction of three domain objects (1)MonitorServletContext the creation and destruction of the domain listener Servletcontextlistener

1) The life cycle of the servlet domain

When to create: Server startup creation

When to destroy: Server shutdown destroy

2) Listener writing steps (emphasis):

A, write a listener class to implement the Listener interface

B, the method of covering the listener

C, need to be configured in Web. XML---Registration

3) How to monitor:

4) configuration file:

5) The main role of the Servletcontextlistener listener

A, initialization work: Initialize object initialization data ----LOAD database-driven connection pool initialization

B. load some of the initialized configuration files ---Spring configuration file

C, task scheduling ----Timer----timer/timertask

(1)MonitorThe httpsession domain was created on the destroyed listener Httpsessionlistener

1) Life cycle of HttpSession objects

When to create: the first time you call request.getsession

when to destroy: Server shutdown destroy session expired manual Destroy

2)

Methods of Httpsessionlistener

(1)MonitorServletRequest domain creation and destruction of listeners Servletrequestlistener

1) ServletRequest life cycle

Create: Request is created every time

Destroy: End of request

2) Method of Servletrequestlistener

1. A common method for monitoring the property changes of three domain objects (1) domain objects:

SetAttribute (Name,value)

---method that triggers the listener to add a property

---How to trigger a listener to modify a property

GetAttribute (name)

RemoveAttribute (name)

---method that triggers the listener to delete properties

(1) Servletcontextattibutelistener Listener

(1) Httpsessionattributelistener Monitor (IBID.) (2) Servletrequestariibutelistenr Listener (IBID.)

1.with theListener associated with the bound object in session (object-aware listener) (1)that will be bound toThere are several states of objects in the session

binding state: An object is placed in the session field

Unbind state: This is the object removed from the session field

passivation State: Is to persist (serialize) objects in session memory to disk

activation state: The object on the disk is restored to session memory again

Interview question: How to optimize the server when the user is right?

(2)binding and Unbinding listenersHttpsessionbindinglistener

(1)passivation and activation of the listenerHttpsessionactivationlistener

You can use the configuration file Specifies the object passivation time ---object for a long time without being passivated

in the Create a context.xml under Meta-inf

<Context>

<!--how long the objects in the maxidleswap:session are not used, passivated--

<!--directory: passivated object files are written to the disk under which directory to configure the Passivated object file in the work/catalina/localhost/passivation file--

<manager classname= "Org.apache.catalina.session.PersistentManager" maxidleswap= "1" >

<store classname= "Org.apache.catalina.session.FileStore" directory= "itcast205"/>

</Manager>

</Context>

Files that are passivated to work/catalina/localhost/

Javaweb Learning Listener Monitoring

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.