How the servlet container works

Source: Internet
Author: User
Tags interface

This article describes the basics of the servlet container. There are two servlet containers, the first one is simple, and the second is written according to the first. In order to make the first container as simple as possible, so did not do very complete. Some of the more complex servlet containers (including TOMCAT 4 and 5) can refer to other data.

The two servlet containers handle simple servlet and StaticResource. You can test it by using the Primitiveservlet in the webroot/directory. A complex servlet can exceed the capacity of these containers, and creating a complex servlet container is not the content of this article, so it is not covered here in detail.

The two application classes are encapsulated under the Ex02.pyrmont package. Before you understand how your application works, you must be familiar with the Javax.servlet.Servlet interface. Let's introduce this interface first. The details of the servlet container service servlet are then described.

Javax.servlet.Servlet interface

Servlet programming, you need to refer to the following two classes and interfaces: Javax.servlet and Javax.servlet.http, where the Javax.servlet.Servlet interface is particularly important in these classes and interfaces. All servlet must implement this interface or inherit the class that implements this interface.

The Servlet interface has five methods, as follows:

 public void init(ServletConfig config) throws ServletException
 public void service(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException
 public void destroy()
 public ServletConfig getServletConfig()
 public java.lang.String getServletInfo()

The Init, service, and destroy methods are the Servlet lifecycle methods. When the servlet class is instantiated, the container loads init to notify the servlet that it has entered the service ranks. The Init method must be loaded for Servelt to receive and request. Programmers can override this method if you want to load a database driver, initialize some values, and so on. In other cases, this method is generally empty.



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.