Functions of httpservlet

Source: Internet
Author: User

The role of httpservlet is:
The HTTP response result is generated based on the HTTP request sent by the customer. Httpservlet must first read the content of the HTTP request. The servlet container is responsible for creating the httprequest object and encapsulating the HTTP request information to the httprequest pair.

This greatly simplifies the workload of HTTP servlet to parse request data.
Without httpservletrequest, httpservlet can only directly process the original string data sent by the Web Client. With httprequest, you only need to call the relevant methods of httpservletrequest to conveniently read the string data.

Common Methods for reading HTTP request information in httpservletrequest are as follows:
Getcookies () return HTTP request cookies
Getheader (string name) returns the header data of the HTTP request specified by the Parameter
Getrequesturi () returns the HTTP request URI
Getquerystring () returns the query string in the HTTP request data
Getmethod () returns the HTTP request method.
The servlet container provides the httpservletresponse object to httpservlet, which can be used to generate parts of the HTTP response. The method provided by httpservletresponse to generate response data Headers

As follows:
Addcookie adds a cookie to the HTTP Response
Setheader (string name, string value) sets the HTTP Response Header. If the header corresponding to the parameter name already exists, the original header data will be overwritten.
Addheader (string name, string value) adds a header to the HTTP response.

Httpservlet service method
The servlet container calls its own method to parse HTTP request information.
1: the Web Client sends an HTTP request to the servlet container;
2: The servlet container parses the HTTP request of the Web Client;
3: The servlet container creates an httprequest object, which encapsulates HTTP request information;
4: Create an httpresponse object in the servlet container;
5: The servlet container calls the service method of httpservlet and transmits the httprequest and httpresponse objects as parameters of the service method to the httpservlet object;
6. httpservlet calls the httprequest method to obtain the HTTP request information;
7. httpservlet calls httpresponse methods to generate response data;
8: The servlet container sends the HTTP servlet response result to the Web Client.

From http://www.blogjava.net/a237359957/archive/2009/03/08/258450.html

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.