Thirteen J2EE technologies-Servlet

Source: Internet
Author: User

Thirteen J2EE technologies-Servlet

Introduction:

Protocol-based request/response service Java class. In general, Servlet is a small program running on the server. Why is it Servlet? Applet indicates a small application, and Server + Applet is Servlet, indicating a small service program.

 

Working Mode:

The client (Web browser) sends a request to the server, and the server starts and calls the Servlet. The Servlet generates a response based on the request and sends it to the server. The server returns an HTTP Response to the client.


Lifecycle:

Procedure

1) client request Servlet

2) instantiate and load to memory

3) initialize the Servlet, init

4) service () customer request;

5) Disable database destroy () destruction.

Init ()

It is executed only once when the server loads Servlet. This method is not repeated no matter how many clients access the Servlet.

Service ()

The core of the Servlet. When the client requests an HttpServlet object, the object will be called and two parameters will be passed-ServletRequest and ServletResponse.

Destroy ()

Same as the init () method, this method is only executed once. It is executed when the server stops and the makeup remover Servlet.

 

Comparison with JSP:

First, Servlet first, and then JSP. Servlet is the basis of JSP, and JSP does not add functions that cannot be implemented by Servlet. JSP implements the static HTML and dynamic HTML hybrid encoding technology, which is more advantageous in writing static HTML, and achieves separation of tasks of different nature. This is their basic difference.

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.