Java EE httpservlet Parsing

Source: Internet
Author: User

As mentioned in the previous article, Genericservlet is a generic implementation of the Servlet and provides an abstract service () method. And our Internet is using the HTTP protocol to communicate, that for this "special" HTTP protocol, there is no corresponding Servlet implementation?

Yes, it is httpservlet, and it inherits directly from Genericservlet, as shown in.

At the same time, as you can see from the image above, HttpServlet supports 7 Http methods by default:Delete, Head, Get, Options, Post, Put, Trace.

Simple Demo code address: Https://github.com/cyhbyw/JavaWEB_atguigu_TongGang

Project Name: Cyhdebugsource_httpservlet

How does httpservlet inherit the Genericservlet and implement the Http protocol support?

It is easy to see that it converts ServletRequest & Servletresponse directly into HttpServletRequest & in the overridden service () method HttpServletResponse, and calls the overloaded service () method.

This overloaded service () method is implemented as follows. Note that the method into the service () method that participates in the previous rewrite is not the same!

At the same time, it obtains the request form from the HttpServletRequest and calls the corresponding doget (), DoPost (), DoPut () and so on.

Take DoPost () as an example, the implementation is as follows; As you can see, the access level is protected and the default implementation is to return the error directly, so this is a method that is open to subclasses to inherit and implement.

If the subclass does not implement the corresponding method, the request results are as shown.

Conversely, to implement different processing of HTTP requests such as GET, put, post, and so on, it becomes very simple, as shown in

The direct implementation of the corresponding GoGet (), DoPost (), DoPut () and other methods can be, and, the entry is HttpServletRequest & HttpServletResponse, which can be easily handled Http-related content.

====================================================

What's next: How does the Dispatcherservlet in SPRINGMVC work?

====================================================

Java EE httpservlet Parsing

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.