Javaweb Understanding the Domain object life cycle through listener

Source: Internet
Author: User

The use of Servletrequestlistener, Httpsessionlistener and Servletcontextlistener can bring request,session, And the life cycle of application.

> Requests: is a request that is destroyed when a response is returned. is created when a request is sent. Note: The process of requesting forwarding is a request object.

Note: Properties placed on the page are not available in the servlet because the request has been destroyed after the page responds.

Note: Redirection is a two request.

> Session: When you first access a JSP or servlet for your web app, you also need to create a session object in that JSP or servlet.

Session Destruction: Session expires, directly call the session Invilidate method, the current Web application is uninstalled (session can be persisted)

  * Close the browser does not mean that the session is destroyed, you can also find the session object in the server via SessionID

> Application: Throughout the life cycle of your current WEB application. When the current web app is loaded, the Application object is created, and the current web app is

Destroys the Application object when unloaded.

Servletcontextlistener

1). What: Monitor the Servlet listener that the ServletContext object was created or destroyed

2). How:

> Create a class that implements the Servletcontextlistener, and implement two of these methods

public class Helloservletcontextlistener implements Servletcontextlistener

> Configuring Listener in the Web. xml file

<listener>

<listener-class>com.java.javaweb.test.HelloServletContextListener</listener-class>

</listener>

3). Why:servletcontextlistener is the most commonly used listener that initializes the relevant resources for the current web app when the current web app is loaded:

Create a database connection pool, create a spring IOC container, read the initialization parameters of the current WEB app ...

4). API:

Method Summary
void contextDestroyed(ServletContextEvent sce)
Notification that, the servlet context is on to being shut down.
void contextInitialized(ServletContextEvent sce)
Notification the Web application initialization process is starting.

Javaweb Understanding the Domain object life cycle through 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.