[Java EE] The invocation process and life cycle of the servlet

Source: Internet
Author: User

In the request header of the HTTP protocol, get the resource to access, find the Web. XML file to find the corresponding servelet

the life cycle of Sevlet

Servletwhen first accessed, the server creates aServletobject that will be called directly after the object is created.Initmethod to initialize, the object that is created will always reside in memory for thisServletaccess to the service, every time to thisServletAccess will result inServicemethod is executed whenWebWhen the application is removed from the container or when the server is shut down,Webdestruction of the applicationServletWill be destroyed, and the server will callServletof theDestroymethods to do some aftercare work

Each time the service () method is invoked, two parameters are passed in:Request object,Response Object

The request object contains the http header and the entity content

the Response object is empty

Call the getwriter (). Write () method of the Response object , toward Response object to write the contents of

The server organizes the contents of the Response object into the Http protocol and returns it to the browser

the inheritance structure of the Servlet

Servlet-Interface defines the basic method that a servlet should have

| -- Genericservlet General Basic Servlet realize, put Service method is designed as an abstract method, which requires subclasses to implement

| -- HttpServlet implemented in the parent class. Service method to determine the current request, call the corresponding doxxx method that requires subclasses to inherit and overwrite the corresponding doget () or doPost () Method

details of the Servlet

A <servlet> can correspond to multiple <servlet-mapping>

<url-partten> can use the * match character, due to the introduction of * , it is possible that a path is multiple Url-partten match, Priority: which is most likely to be found,*. the suffix has the lowest priority

Under <servlet> can be configured <load-on-start-up> can be used to specify the boot order

[Java EE] The invocation process and life cycle of the servlet

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.