Request and response, servletrequest in servlet

Source: Internet
Author: User

Request and response, servletrequest in servlet
In the B/s architecture, there are requests from the browser and response server feedback. The bottom layer is the TCP/IP protocol and the application layer is the http protocol. In the tomcat server, version 6 uses the http1.1 protocol. When the server sends a request, it is possible to load get and post requests (doget requests are placed in URLs and can be parsed using getparmeter, because tomcat regards each webpage request as an object, therefore, it is an object-oriented (HttpServletRequest) encapsulation, and doget and dopost are parsed accordingly. The main APIs are as follows:

Core APIs:

Request Line:

Request. getMethod (); request Method

Request. getRequetURI ()/request. getRequetURL () request Resource

Request. getProtocol () request http Protocol version

Request Header:

Request. getHeader ("name") obtains the request value based on the request Header

Request. getHeaderNames () Get all request header names

Entity content:

Request. getInputStream () Get object content data

Encoding is involved in the request. setenconding is acceptable, bytecode can be forcibly converted, and xml configuration is also acceptable.

For HTTP servletresponse server feedback, encoding issues must also be involved. You can declare it in the response header. Others can also force conversion of bytecode (like socket programming, what base64 encryption, what memory is especially new ). Various browser feedback codes, such as 404,500, have also been roughly learned.

Common response Headers)

Location: http://www.it315.org/index.jsp-represents the redirected address, which is used together with the 302 status code. Server: apache tomcat --- indicates the Server type Content-Encoding: gzip -- indicates the data compression type Content-Length that the Server sends to the browser: 80 -- indicates the length of the data sent from the server to the browser Content-Language: zh-cn -- indicates the Language Content-Type: text/html supported by the server; charset = GB2312 -- indicates the data type and content encoding Last-Modified: Tue, 11 Jul 2000 18:23:51 GMT -- indicates the Last modification time of server resources Refresh: 1; url = http://www.it315.org -- indicates a timed refresh of Content-Disposition: attachment; filename=aaa.zip -- tells the browser to open resources in download mode (used when downloading files) Transfe R-Encoding: chunkedSet-Cookie: SS = Q0 = 5Lb_nQ; path =/search -- indicates the cookie information sent by the server to the browser (used by session management) Expires: -1 -- indicates notifying the browser not to Cache-Control: no-cachePragma: no-cacheConnection: close/Keep-Alive -- indicates the connection status between the server and the browser. Close: close connection keep-alive: Save connection

 

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.