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.