Java web servlet and javawebservlet

Source: Internet
Author: User

Java web servlet and javawebservlet

Servlet essential for pitfall(O (partition _ partition) O ha !)

Two questions: What is it? How to use it?

The first question: what?

Servlet is a technology provided by sun to develop dynamic web resources. sun provides a servlet interface in its API. It can be understood that the native servlet is an interface. When it comes to interfaces, we should think that we must implement them before we can use them. The servlet interface is no exception, of course, in terms of concept, servlet refers to the API interface provided by sun, which is commonly known as the convention. Now, servlet refers to the class that implements this interface, generally, this servlet refers to the servlet implemented by us.

Okay. The first question is over. servlet is an interface, and the servlet is a class that implements this interface. (Done in one sentence)

The second question: how?

Here we will first talk about the purpose of servlet. Who is using it? Servlet is a small program running on the server (from Baidu encyclopedia). It is used by the server. servlet = Service + Applet, service refers to the Service, and applet refers to the small program, servlet refers to a service applet. (The following servlets refer to servlet applets that have implemented servlet interfaces.)

Next, let's talk about how to use servlet,

There are roughly five steps, and each step is described in detail later.

The Servlet applet is called by the server. After the server receives the Servlet access request from the client:
① The server first checks whether the Instance Object of the Servlet has been loaded and created for the first time. If yes, perform Step 4. Otherwise, perform step 2.
② Load and create an instance object for the Servlet.
③ Call the init () method of the Servlet instance object.
④ Create an HttpServletRequest object that encapsulates the HTTP request message and an HttpServletResponse object that represents the HTTP Response Message. Then call the Servlet service () method and pass the request and response object as parameters.
⑤ Before the WEB application is stopped or restarted, the Servlet engine will uninstall the Servlet and call the Servlet's destroy () method before uninstalling it.

Step 1: Normally, the server will create only one servlet object for the browser's requests. This object will be stored in the memory all the time and respond to the requests sent by the browser, until you close the webpage or call the servlet method to exit, the first time it means that you open the webpage until it is closed and exit the browser, the corresponding servlet object will call the destory () method, destroy the servlet object.

Step 2: Create a servlet object

Step 3: Call the initialization method of an object,

Part 4: Create a request object (HttpServletRequest) and response object (HttpServletResponse) by the web Container (the service program that calls the servlet applet), and call the service () method of the servlet applet, the newly created request object and response object are passed as parameters. For details about the process, see who is reading and writing the information. Black indicates the request process, blue represents the response process (the figure is too ugly, please forgive me !)

 

 

 

 

 

Today, let's write down what the servlet is and how it works. Next we will talk about several methods contained in the servlet applet (init ();, destory (); doget ();, dopost ();, and other methods );

Thank you for your attention!

 

 

 

    

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.