Details about all attributes of the response object in Jsp

Source: Internet
Author: User

Interface: javax. servlet. http. httpServletResponse, whose parent interface is ServletResponse, and ServletResponse only has one HTTP ServletResponse subinterface. The main reason is that the current J2EE WEB program uses HTTP as the main communication protocol.
Functions of the response object:

1. setHeader (String name, String value)
Sets the value of the specified HTTP file. If the value already exists, the new value overwrites the original value.
Set the header information: response. setHeader ("header information content", "header information Parameters ");
Frequently Used refresh, such as response. setHeader ("refresh", "1 ");
Jump in seconds: response. setHeader ("refresh", "2: URL = XXX ");
2 redirection -- response jump: response. sendRedirect ("Jump address ");
(Redirection will lose all request parameters. The effect of redirection is exactly the same as that of re-entering a new address in the address bar and then pressing the Enter key, that is, the second request is sent)
After this statement is executed, the page address also changes to the address after the jump
FAQ during the interview: The difference between the two jumps: the address bar does not change-server jump
Jump immediately after the jump statement is executed-subsequent code will not be executed
Note: If you use forward to jump, you must release all resources before the jump;
When forward is used, the property set for the request (setAttribute) can still be retained to the next page.
PASS Parameters
Response. sendRedirect ("Jump address "):
Address Bar change-client jump
Jump to the page after all the code is executed
The request attribute cannot be saved, the address bar is changed, and the client jumps
Passing parameters through URL address Rewriting
3. addCookie (Cookie cook)
Add a Cookie object to save client user information.
Cookie is a group of resources stored on the client on the server.
Use cookies to save the password or how long does it take to enter the password?
Cookie setting method: Public Void addCookie (Cookie)
Cookie is set to the client through the server -- response
If you want to obtain the Cookie -- request on the server side
The request object contains the Public Cookie [] getCookies () method.
When you use the request object to retrieve all cookies, JSESSIONID is displayed, indicating the unique client ID on the server. This value is set after the client first accesses the server.
By default, the Cookie is only valid for the current browser. If you need to stay on the computer for a long time, you can set the Cookie retention time by setting the maximum Cookie retention time method: setMaxAge ()

1. addHeader (String name, String value)
Add the HTTP File Header. the Header will be uploaded to the client. If the same Header already exists, the existing Header will be overwritten.

2. containsHeader (String name)
Checks whether the specified HTTP File Header already exists, and returns a Boolean value indicating true or false.

3. sendError (int)
Sends an error message to the client.

4. setHeader (String name, String value)
Sets the value of the specified HTTP file. If the value already exists, the new value overwrites the original value.

Related Article

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.