Servlet Study Notes (1) -- Overview

Source: Internet
Author: User

1. servlet is a Java program that can be deployed on the Web server.

2. For servlet programming, the following two classes and interfaces must be referenced: javax. servlet and javax. servlet. http. Among these classes and interfaces, javax. servlet. servlet interfaces are particularly important. All servlets must implement this interface or inherit the classes that have implemented this interface.

3. The servlet interface has five methods:

1) Public void Init (servletconfig config) throws servletexception
2) Public void Service (servletrequest request, servletresponseresponse) throws servletexception, java. Io. ioexception
3) Public void destroy ()
4) Public servletconfig getservletconfig ()
5) Public java. Lang. String getservletinfo ()

4. The init, service, and destroy methods are servlet lifecycle methods. After the servlet class is instantiated, the container loads init to notify the servlet that it has entered the service column. The init method must be loaded, and the servelt can receive and request. To load the database driver and initialize some values, the programmer can rewrite this method. In other cases, this method is generally null.

5. The service method is called by the servlet container to allow the servlet to respond to a request. The servlet container passes the javax. servlet. servletrequest object and javax. servlet. servletresponse object. The servletrequest object contains the HTTP request information of the client. The servletresponse encapsulates the servlet response. With these two objects, you can write code that requires servlet service and customer request.

6. The Container calls the destroy method before deleting the servlet instance from the service. When the servlet container is closed or the servlet container requires more memory, it is called. This method is called only when all threads in the servlet service method exit, or when it times out. After the servlet container calls the destroy method, it no longer calls the servlet service method.

7. the destroy method gives the servlet the opportunity to clear all idle resources (such as memory, file processing, and threads) to ensure that the continuous state of the memory and the current state of the servlet are synchronized.

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.