11 Reponse objects

1.HTTP agreement:

(1) Request message: The client sends data to the server side
 data format:
  1. Request line
  2. Request header
  3. Request blank line
  4. The body of the request
(2) Response message: The server sends to the client data
* data format:
  1. the response line
    1. composition: protocol / version response status codes status code description
    2. response status code: the server tells the client browser to the current state of a request and response.
      1. The possible status codes are three digit
      2. Classification:
        <. 1> 1xx: the server receiving the client message, but did not receive complete, wait a period of time, multi-state transmission 1xx code
        <2> 2xx: Success. Representative: 200 is
        <. 3> 3xx: Redirection. Representative: 302 (redirect), 304 (cache access)
        <. 4> 4xx: Client Error.
          Representative *:
            * 404 ( request path without corresponding resources )
            * 405: doXxx embodiment no corresponding request method
        <5> 5xx: Server side error. Representative: 500 (internal server abnormal)


  2 response header:
    1. Format: first name: value
    2. Common response headers:
      1. Content-Type : The server tells the client of this body response data format and encoding format
      2. Content-disposition: Open the server tells the client what format the response body data
      * value:
      * in-Line: default value, within the current open page
      * attachment; filename = xxx: open response body attachment. Download
  3. Response blank line
  4. Response body: data transmission

2.Response Object
function: Setup Response message

Note: The following are members of the method of HttpServletResponse.
(1) is provided in response to row
  1. Format: the HTTP / 1.1 OK 200 is
  2. Set status code: setStatus (int SC)
(2) set the response header: the setHeader (String name, String value)

(. 3) is provided in response to the body:
the use of step :
  1. obtain an output stream
    * character output stream: PrintWriter getWriter ()

    * Output stream of bytes: ServletOutputStream getOutputStream ()

  2. Using the output stream, the output data to the client browser

Case I: Redirect

Redirection process:

  (1) the client browser sends an http request

  (2) web server 302 transmits the status code in response to receiving a new location and a corresponding to the client browser

  (3) the client browser 302 in response to a discovery, and then automatically sends a new http request, the request url is the new address location. Server based on the request sent to the customer to find resources. Here location can be redirected to any URL, the browser since it is re-issued the request, the request would have no concept of the transfer. In the client browser displays the path bar to redirect its path, customers can observe the change of address. Redirect the browser to do a behavior is at least twice the access request.

 

Guess you like

Origin www.cnblogs.com/luckyplj/p/11222265.html