Owning interface: Javax.servlet.http.HttpServletResponse, whose parent interface is Servletresponse, And Servletresponse now has only one httpservletresponse sub-interface, the main reason is that now the Java EE Web program mainly with the HTTP protocol as the main communication protocol.
functions of the Response object:
1. SetHeader (string name, String value)
Sets the value of the specified HTTP file, and if the value already exists, the new value overwrites the original old value.
Set Header information: Response.setheader ("header information content", "header information parameter");
Commonly used refresh refreshes, such as: Response.setheader ("Refresh", "1");
After a few seconds to jump: Response.setheader ("Refresh", "2:url=xxx");
2 redirect--response jump: Response.sendredirect ("Jump Address");
(redirection loses all request parameters, using the effect of redirection, with the same effect as entering the new address in the address bar and then pressing ENTER), that is, sending a second request.
After this statement is executed, the page address becomes the address of the jump
Common problems in interviews: the difference between two jumps: the address bar does not change--belongs to the server-side jump
Jump immediately after execution to a jump statement--the code that follows will no longer execute
Note: If you use forward jump, you must release all resources before jumping;
When using forward, the properties of the request settings (setattribute) can still be persisted to the next page
By passing parameters
Response.sendredirect ("Jump Address"):
Address bar change-client jump
All code on the page is finished before you jump
The request attribute cannot be saved, the address bar is changed, and the client jumps
Passing arguments to a URL address override
3.addCookie (Cookie Cook)
Add a cookie object to hold the client user information.
Cookies are a set of resources that the server side holds on the client
The ability to save passwords through cookies or how long to enter them without requiring a password
Method of setting Cookies: Public Void addcookie (Cookie cookie)
Cookies are set up on the server side to the client--response
If you want to get cookie--request on the server side
There is a public cookie[] getcookies () method in the Request object
Jsessionid appears when you use the Request object to obtain all cookies, representing the number of the unique client on the server, which is set after the client first accesses the server side
By default, cookies are only valid for the current browser, and if you need to stay on your computer long, you can set the save time for the cookie by setting the maximum cookie retention method: Setmaxage ()
1.. addheader (string name, String value)
Add HTTP header information, the header will be uploaded to the client, overwriting the existing header if the same header exists.
2. Containsheader (String name)
Determines whether the HTTP file header for the specified name already exists, and then returns the true Boolean value.
3. Senderror (int)
Send the wrong message to the client.
4.. setheader (string name, String value)
Sets the value of the specified HTTP file, and if the value already exists, the new value overwrites the original old value.