Javaweb part3----An explanation of the HTTP protocol, and the classes and methods of request response in Java

Source: Internet
Author: User

HTTP protocol Detailed
Requsert Headers The request information sent by the browser to the server
Get/myweb/persons.html http/1.1 (required)
host:localhost:8080
Connection:keep-alive
Accept supported formats:
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
User-agent: Browser-compatible version
Accept-encoding: Supported compression encodings
ACCEPT-LANGUAGE:ZH-CN Simplified Chinese

Response headers server responds to browser information
http/1.1 OK
OK
404 on behalf of not found
403 Client not authorized
302 redirect Movedtemporarily temporarily moved the address of the Localtion page webpage;
Internal Server error Server Internal error
The HTTP protocol status code indicates different problems respectively;

Browser requests the difference between get and post
1.GET put the information directly behind the GET and post put the information in the newspaper style inside
2.GET file server is not modified when the cache is read directly. The post is a new request every time.

Relative path and absolute path
"." Represents the current folder
".." Represents the previous level of the directory
"/" means the root directory
Relative path refers to the path relative to the referenced file;
Absolute path refers to the path relative to the root directory;

Class objects and methods in Java that process server requests.
HttpServletResponse
Sendredirect () redirect redirects to a new address
setContentType Text/html;charset=utf-8
Setcharacterencoding Utf-8
Getoutputstream the stream of the reported style that gets the response

Method of HttpServletRequest.
QueryString get? What's behind I=5&j=8 localhost:8080/myweb/chengyi?i=5&j=8
Req.getcontextpath () Contextpath/myweb
REQ.GETREMOTEADDR () remoteaddr IP address
Req.getrequesturi () requesturi/myweb/test root directory starting with path without parameters
Req.getinputstream () Gets the flow of the request body

Getservletcontext (). Getrealpath () Gets the path under the server folder. Not the source code path

Javaweb part3----An explanation of the HTTP protocol, and the classes and methods of request response in Java

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.