public void filedownload(httpservletresponse response) throws Exception {
ServletContext context = This.getservletcontext ();
String Path = Context.getrealpath ("/download/awf.jpg");
String filename = path.substring (path.lastindexof ("\") + 1);
If the download file is a Chinese file, the filename needs to be encoded by URL;
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 Use :
Beanutils.pupulate (bean,mapinstance);////Map load the value of key and key corresponding to the bean attribute in Bean,map;
Beanutils.copyproperties (bean,mapinstance);//copy map to Bean;
Forwarding is a request that 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);//Send messages to Message page for display;
<2>response.setheader ("Refresh", "3;url= '/webtwo/index.jsp '");
Response.getwriter (). Write ("Congratulations login success, if there is no relay, please click the hyperlink <a href= ' webtwo/index.jsp '");
Program code:
Program to what code table output, you must control what the browser to open the Code table;
Using meta technology in HTML to simulate HTTP response headers to control the behavior of the browser;
Out.write ("<meta http-equiv= ' content-type ' content= ' Text/html;charset=utf-8 ' >"). getBytes ());
Response.setcharacterencoding ("UTF-8");/set the code table used by the response to control what code table the response writes data to the browser;
Response.setheader ("Content-type", "text/html;charset=utf-8");//Specify what code table the browser opens the data in;
Quite a few words above:
Response.setcontenttype ("Text/html;charset=utf-8");
Response.setdateheader ("Expires", System.currenttimemillis () + 1000*3600);/Set session effective time 10 minutes;
Response.getwriter (). write (data); Response.getwriter ()--> return printwriter;
Response.setheader ("Refresh", "3");