Java EE----re-review servlet

Source: Internet
Author: User

Recently faced with looking for a job, have to review Java Servelt. Find the LZ's basic skills is still very poor

1. Each servlet must implement the Servlet interface, Genericservlet is a generic, protocol-neutral servlet that implements the Servlet interface, and HttpServlet inherits and Genericservlet, So HttpServlet also implements the Servlet interface, so the servlet we define only needs to inherit the HttpServlet parent class.

2. A service method is defined in the Servlet interface, and the method is implemented by HttpServlet the ServletRequest and servletresponse into HttpServletRequest and HttpServletResponse. The service method is then overloaded.

3. In the service method, first obtain the method name of the request, and then call the corresponding Doxxx method according to the method name, for example, the request method is get, then go to call the Doget method, the request method is POST, then call the DoPost method.

4. The methods provided in the HttpServlet class, such as Doget, DoPost, and so on, all return error messages directly, so we need to override these methods in our own defined Servlet class .

5. Servelt the relationship between core APIs UML diagram:

6. The start of the servlet (default is a singleton servlet) (the Init method is executed the first time the servlet is called by default)

• The servlet container loads the servlet at the following times:
–servlet loading some servlets automatically when the container starts
– After the servlet container is started, the customer makes the first request to the servlet
After the –servlet class file is updated, remount the servlet

After the servlet is loaded, the servlet container creates a servlet
And call the Servlet's init () method to initialize. In
The Init method is only called once throughout the servlet's life cycle.

A) enable the servlet container to automatically load some servlets (Configure the Load-on-startup property) when it starts

    

7 for Request.setattribute ("key", "value"); is actually maintaining a concurrenthashmap.

Because the request object was created by Tomcat. So you have to punch Tomcat in the source code to see.

  

Java EE----re-review servlet

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.