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.