Servlet Response object, servletresponse

Source: Internet
Author: User

Servlet Response object, servletresponse

The following method can be used to set the HTTP Response Header in the Servlet program. These methods are available through the HttpServletResponse object.

 

1 StringEncodeRedirectURL(Stringurl)

Encode the specified url used in the sendRedirect method, or if the encoding is not required, the returned URL remains unchanged.

2 StringEncodeURL(Stringurl)

Encode the specified URL containing the session ID, or if the encoding is not required, the returned URL is not changed.

3 booleanContainsHeader(Stringname)

Returns a Boolean value indicating whether a named Response Header has been set.

4 booleanIsCommitted()

Returns a Boolean value indicating whether the response has been submitted.

5 voidAddCookie(Cookiecookie)

Adds the specified cookie to the response.

6 voidAddDateHeader(Stringname, long date)

Add a response header with a given name and date value.

7 voidAddHeader(Stringname, String value)

Add a response header with a given name and value.

8 voidAddIntHeader(Stringname, int value)

Add a response header with a given name and integer.

9 voidFlushBuffer()

Force any content in the buffer to be written to the client.

10 voidReset()

Clear any data in the buffer, including the status code and header.

11 voidResetBuffer()

Clears the content of the basic buffer in the response. The status code and header are not cleared.

12 voidSendError(Intsc)

Use the specified status code to send an error response to the client and clear the buffer zone.

13 voidSendError(Intsc, String msg)

Sends an error response to the client using the specified status.

14 voidSendRedirect(Stringlocation)

Use the specified URL to send a temporary redirect response to the client.

15 voidSetBufferSize(Intsize)

Set the preferred buffer size for the response body.

16 voidSetCharacterEncoding(Stringcharset)

Sets the character encoding (MIME Character Set) for the response sent to the client, for example, the UTF-8.

17 voidSetContentLength(Intlen)

Set the Length of the Content body in the HTTP Servlet response. This method sets the HTTP Content-Length header.

18 voidSetContentType(Stringtype)

If the response has not been submitted, set the content type of the response sent to the client.

19 voidSetDateHeader(Stringname, long date)

Set a response header with a given name and date value.

20 voidSetHeader(Stringname, String value)

Sets a response header with a given name and value.

21 voidSetIntHeader(Stringname, int value)

Sets a response header with a given name and integer.

22 voidSetLocale(Localeloc)

If the response has not been submitted, set the response region.

23 voidSetStatus(Intsc)

Set the status code for the response.

24 OutputStreamGetOutputStream()

Get a stream that writes data to the Response object. When the tomcat server responds, it will write the data in the Response to the browser.

 

The following summarizes the most useful HTTP 1.1 Response Header returned from the Web server to the browser. The following attributes can be set using the setHeader method, such as response. setHeader ("Content-type", "text/html; charset = UTF-8"), send a response header to the browser, set the browser's decoding method to UTF-8, in fact set the sentence, the Response encoding method is also set to UTF-8 by default, it is best to combine the two sentences in development to use

Response. setHeader ("refresh", "1000; URL = http: // localhost: 8080/servlet") // jump to the specified page response in 1 second. setIntHeader ("Refresh", 5) // set the auto-Refresh loading time to 5 seconds.
 

AllowThis header specifies the request methods supported by the server (such as GET and POST ).

Cache-ControlThis header specifies the situations in which the response document can be safely cached. Possible values include public, private, or no-cache. Public means that the document is cacheable. Private means that the document is Private for a single user and can only be stored in the Private (non-shared) cache. no-cache means that the document should not be cached.

ConnectionThis header indicates whether the browser uses a persistent HTTP connection. The value close indicates that the browser does not use persistent HTTP connections. The value keep-alive indicates that persistent connections are used.

Content-DispositionThis header allows you to request the browser to ask the user to save the response to a disk with a given name.

Content-EncodingDuring transmission, this header specifies the page encoding method.

Content-LanguageThis header indicates the language used for document writing. For example, en, en-us, and ru.

Content-LengthThis header indicates the number of bytes in the response. This information is required only when the browser uses a persistent (keep-alive) HTTP connection.

Content-TypeThis header provides the MIME (MultipurposeInternet Mail Extension) Type of the Response document.

ExpiresThis header specifies the expiration time of the content. After this, the content will not be cached.

Last-ModifiedThis header indicates the last modification time of the document. Then, the client can cache the file and provide a date through the If-Modified-Since request header information in future requests.

LocationThis header information should be contained in all responses with status codes. Within 300 s, this will notify the address of the browser document. The browser automatically reconnects to this location and obtains new documents.

RefreshThis header specifies how the browser requests the updated page as soon as possible. You can specify the number of seconds for page refresh.

Retry-AfterThis header information can be used with the 503 (Service Unavailable) response, which tells the client how long it can repeat its requests.

Set-CookieThe header information specifies a cookie associated with the page.

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.