2016.8.23 the first small pen (Java Web servlet life cycle)

Source: Internet
Author: User

the life cycle of the servletExecution process: constructor-"Init Method-" Loop "service method"-"Destroy Method" (normal off Tomcat) * 1. The constructor executes first (creating the Servlet:init,service,destroy method), all of which are non-static methods. You must use an object to make a call * 2. A servlet class has only one object in the life cycle * The 3.service method executes on each request * The 4.destroy method executes normally only when Tomcat shuts down normally and does not execute if no access is closed * Do not write wrap-up work in the Destroy method * The 5.servlet class must be decorated with public, and the servlet constructor must be publicly parameterless * (the following programs are written in order of execution)Examples of programs:public class Servlet_life extends HttpServlet {public servlet_life () {System.out.println ("constructor");    } public void Init () throws Servletexception {System.out.println ("Run init ()"); } protected void Service (HttpServletRequest arg0, HttpServletResponse arg1) throws Servletexception, Ioexcep    tion {System.out.println ("service: Hello");    } public void Destroy () {System.out.println ("in Progress Destroy ()"); }

2016.8.23 the first small pen (Java Web servlet life cycle)

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.