Public voidFiledownload(HttpServletResponse response) throws Exception {
ServletContext context = this. getServletContext ();
String path = context. getRealPath ("/download/awf.jpg ");
String filename = path. substring (path. lastIndexOf ("\") + 1 );
// If the downloaded file is a Chinese file, the file name must be url encoded;
Response. setHeader ("Content-disposition", "attachment; filename =" + URLEncoder. encode (filename, "UTF-8 "));
InputStream in = new FileInputStream (path );
Int len = 0;
Byte [] buffer = new byte [1024];
OutputStream out = response. getOutputStream ();
While (len = in. read (buffer)> 0 ){
Out. write (buffer, 0, len );
}
In. close ();
Out. close ();
}
BeanUtils:
BeanUtils. pupulate (bean, MapInstance); // load the bean with map. The map contains the key corresponding to the bean attribute and the value corresponding to the key;
BeanUtils. copyProperties (bean, MapInstance); // copy map to bean;
A forward request uses the same response and request;
Page jump:
<1> String message = "<meta http-equiv = 'refresh' content = '3; url =/webTwo/index. jsp '> <a href = 'webtwo/index. jsp '> AAAA </a> ";
This. getServletContext (). setAttribute ("message", message );
This. getServletContext (). getRequestDispatcher ("/message. jsp"). forward (request, response); // bring the message to the message page for display;
<2> response. setHeader ("refresh", "3; url = '/webTwo/index. jsp '");
Response. getWriter (). write ("congratulations, the logon is successful. If there is no transit, click the hyperlink <a href = 'webtwo/index. js'> AAAA </a> ");
Program code:
// What code table the program outputs must control which code table the browser opens;
// Use meta Technology in html to simulate http response headers to control browser behavior;
// Out. write ("<meta http-equiv = 'content-type' content = 'text/html; charset = UTF-8 '>". getBytes ());
Response. setCharacterEncoding ("UTF-8"); // set the code table used by response to control the code table in which response writes data to the browser;
Response. setHeader ("Content-type", "text/html; charset = UTF-8"); // specifies the code table in which the browser opens the data;
// Equivalent to the above two sentences:
// Response. setContentType ("text/html; charset = UTF-8 ");
Response. setDateHeader ("expires", System. currentTimeMillis () + 1000*3600); // set the session validity period to 10 minutes;
Response. getWriter (). write (data); Response. getWriter () --> return PrintWriter;
Response. setHeader ("refresh", "3 ");