HttpServletResponse-------Brain Stump Note 2

Source: Internet
Author: User
Tags response code

HttpServletResponse Interface

go on ..... Gnawing << Unique Architecture: Java Web Development application >> Good memory is better than bad writing. Make notes, deepen impressions.

A. Status line

Generate Status Response code

The 1.setStatus method can set the status code of any HTTP response message and generate a response status line.

2.sendRedirect Method Response Status Code 302

3.sendError method used to send the error message status code

Two. Response message header

Set the response message header (the response message header consists of field and field values)

The 1.addHeader and SetHeader methods are used to set all fields of the HTTP response message header

2.addIntHeader and Setintheader methods specifically set integer field values

3.addDateHeader and Setdateheader methods set Date field values

The 4.setContentType method is used to set the MIME type of the servlet's response body (the value of the Content-type field for the HTTP protocol)

5..setCharacterEncoding method Set the character set portion of the Content-type field

6.setContentLength method sets the size of the body (in bytes) (File size value)

The 7.containsHeader method is used to detect whether a field name exists in the response message header

Three. Response body

The 1.getWriter method is used to return a character output stream object created by the servlet engine

The response body is easily returned to the client, and the response body is also automatically converted based on the character encoding format specified by the Content-type of the response message header, and the object response body encoding must be set charset before the Getwriter method is called, otherwise it cannot be encoded correctly.

The 2.getOutputStream method is used to return a byte output stream object created by a servlet engine

The Getoutputstream method returns a Servletoutputstream object

A. You can return any response body (including image, video, and other binary data) through this object

B. can also return character text response body

Another day has passed. Go ahead!!! Every day we take a few steps forward, we will be more and more close to the dream!!! Ha ha

HttpServletResponse-------Brain Stump Note 2

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.