| 发表于:2007-08-01 08:49:45 楼主 |
页面代码 <%@ page language= "java " contenttype= "text/html; charset=gb2312 " import= "java.net.*,java.io.* " %> <% response.setcontenttype( "application/x-download "); string filename = request.getparameter( "filename "); filename = new string(filename.getbytes( "iso8859-1 "), "gb2312 "); string filenamedisplay = urlencoder.encode(filename, "utf-8 "); string filenamedownload =this.getclass().getclassloader().getresource( "/ ").getpath()+ "../../temp/ "+filename; system.out.print(filenamedownload); response.addheader( "content-disposition ", "attachment;filename= " + filenamedisplay); outputstream output = null; fileinputstream fis = null; try { output = response.getoutputstream(); fis = new fileinputstream(filenamedownload); byte[] b = new byte[1024]; int i = 0; while((i = fis.read(b)) > 0) { output.write(b, 0, i); } output.flush(); } catch(exception e) { system.out.println( "error! "); e.printstacktrace(); } finally { if(fis != null) { fis.close(); fis = null; } if(output != null) { output.close(); output = null; } } %> |
|
|
|
|