The response object of the servlet

Source: Internet
Author: User

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

1 String encoderedirecturl(StringUrl)

Encodes the specified URL used in the Sendredirect method, or if the encoding is not required, the return URL is unchanged.

2 String encodeurl(StringUrl)

Encodes the specified URL that contains the session ID, or if the encoding is not required, the return URL does not change.

3 Boolean Containsheader(Stringname)

Returns a Boolean value that indicates whether the named response header has been set.

4 Boolean iscommitted()

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

5 void Addcookie(Cookiecookie)

Adds the specified cookie to the response.

6 void Adddateheader(stringname, Long date)

Adds a response header with the given name and date value.

7 void AddHeader(Stringname, String value)

Adds a response header with the given name and value.

8 void Addintheader(stringname, int value)

Adds a response header with the given name and integer value.

9 void Flushbuffer()

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

Ten void reset()

Clears any data that exists in the buffer, including the status code and header.

void Resetbuffer()

Clears the contents of the underlying buffer in the response, without clearing the status code and headers.

void senderror(INTSC)

Sends an error response to the client using the specified status code, and clears the buffer.

void Senderror(INTSC, String msg)

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

sendredirectVoid (stringlocation)

Sends a temporary REDIRECT response to the client using the specified redirect location URL.

void setbuffersize(intsize)

Sets the preferred buffer size for the response body.

setcharacterencodingVoid (stringcharset)

Sets the character encoding (MIME character set) of the response that is sent to the client, for example, UTF-8.

+ void setcontentlength(Intlen)

Sets the length of the content body in the HTTP Servlet response, which sets the HTTP Content-length header.

setcontenttypeVoid (StringType)

If the response has not yet been committed, set the content type of the response that is sent to the client.

void Setdateheader(stringname, Long date)

Sets a response header with the given name and date value.

void SetHeader(Stringname, String value)

Sets a response header with the given name and value.

$ void Setintheader(stringname, int value)

Sets a response header with the given name and integer value.

setLocaleVoid (localeloc)

If the response has not yet been committed, set the region of the response.

setStatusVoid (INTSC)

Set the status code for the response.

OutputStream getoutputstream()

Gets a stream that writes data to the response object, and when the Tomcat server responds, the data in the response is written to the browser

The following summarizes the most useful HTTP 1.1 response headers returned from the WEB server side to the browser. The following properties can be set using the SetHeader method, such as Response.setheader ("Content-type", "Text/html;charset=utf-8"), sending a response header to the browser, Set the browser decoding method for UTF-8, in fact, set the sentence, but also the default setting of the response encoding method for UTF-8, the best two sentences in the development of a combination of use

Response.setheader ("Refresh", "1000; Url=http://localhost:8080/servlet ")  //1 seconds after jump to the specified page response.setintheader (" Refresh ", 5)//Set refresh Auto load time to 5 seconds

Allow this header information specifies the request methods (GET, POST, etc.) that the server supports.

Cache-control This header information specifies under what circumstances the response document can be safely cached. Possible values are: public, private, or no-cache, and so on. Public means that documents are cacheable, private means that documents are private documents for individual users and can only be stored in private (non-shared) caches, no-cache means that documents should not be cached.

Connection This header information indicates whether the browser uses a persistent HTTP connection. A value of close indicates that the browser does not use persistent HTTP connections, and the value keep-alive means using persistent connections.

content-disposition This header information allows you to request that the browser require the user to save the response to disk with a file of the given name.

content-encoding This header information specifies how the page is encoded during the transfer process.

Content-language This header information represents the language in which the document was written. For example, en, en-us, RU, etc.

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

Content-type This header information provides the MIME (multipurposeinternet Mail Extension) Type of the response document.

Expires This header information specifies when content expires, after which the content is no longer cached.

last-modified This header information indicates the last modification time of the document. The client can then cache the file and provide a date through the If-modified-since request header information in a later request.

Location This header information should be included in all responses with status codes. Within 300s, this notifies the address of the browser document. The browser will automatically reconnect to this location and get a new document.

Refresh This header information specifies how the browser should request an updated page as soon as possible. You can specify the number of seconds to refresh the page.

Retry-after This header information can be used in conjunction with the 503 (Service Unavailable services unavailable) response, which tells the client how long it will be possible to repeat its request.

Set-cookie Header information Specifies a Cookie associated with the page.

The response object of the servlet

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.