Genericservlet and HttpServlet

Source: Internet
Author: User

1 Genericservlet is the implementation class of the Servlet interface and the ServletConfig interface, but an abstract class in which service is an abstract method

2 If the new Servlet program inherits directly from Genericservlet, it will be more concise to develop

3 Specific implementations:

1) This class declares a member variable of type ServletConfig, which is initialized in the Inti (ServletConfig) method.

2) method of implementing ServletConfig interface using ServletConfig member variable method

3) defines an init () method, which is called in the Inti (ServletConfig) method, and subclasses can directly override the Init () method, where the servlet initialization is implemented.

4) It is not recommended to overwrite Init (servletconfig) directly, because if you forget to write Super.init (ServletConfig) and also call the method of the ServletConfig interface, a null pointer exception will occur

5) The new Init () is not the life cycle method of the servlet, and Init (ServletConfig) is the life cycle approach

1 HttpServlet Inheritance Genericservlet

2 convert ServletRequest () and Servletresponse () to HttpServletRequest () and HttpServletResponse () in service () and invoke the overloaded service ( Httpservletrequest,httpservletresponse), using Request.getmethod () in this method to get the request method, call the Doxxx () method

3 actual development, directly inherit HttpServlet, and rewrite the Doxxx () method according to the request method

Genericservlet and HttpServlet

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.