an object request is a request, and the response from the response object.
1 HttpServletResponse Features
The response function is divided into the following four objects:
l setting response headers; the addHeader ( "REFRESH", ". 5; the URL = XXXX");
l transmitting status code; the sendError (404);
l disposed response body; getWriter (). Print ( "fdsfdsa");
l redirection: sendRedirect ( "path");
2 Set status codes and other methods
response.setContentType ( "text / html; charset = utf-8"): to set the response type html, encoded as utf-8, processing of garbled text display corresponding page;
l response.setCharacterEncoding ( "UTF-. 8"): If the response type is text, you need to set the encoding type of the text, and then use the browser to interpret the coded text. Note that if the contentType is not set, then the browser will think contentType to text / html, if not set the encoding, the default is ISO-8859-1 encoding. So these two points must be set before the response returns the result to use.
response.setStatus (200): Set a status code;
l response.sendError (404, "the resources you are looking for does not exist"): When a transmission error status code, Tomcat will jump to the page to fix the error, but you can error message is displayed.
Setting response headers 3
response.setHeader ( "contentType", " text / html; charset = utf-8"): () function setContentType same method. the setContentType () method belongs convenient method;
Refresh (Timing redirection):
l response.setHeader ( "the Refresh", ". 5; the URL = HTTP: //www.baidu.com"): 5 seconds automatically jump to the homepage Baidu .