Excerpt from: http://blog.csdn.net/wangzhi_821/article/details/5047777
File download often appears the following problems: Response.setheader ("Content-disposition", "attachment; Filename=" +as+ ");
If the as directly in the Chinese name, it will be directly on the IE page open Excel file (pop-up will open in the IE page opens, note at this time, "Do you want to open or save this file?" ", the name will show a similar cak .... The name of the implementation is not the normal *.xls format name):
Instead of popping up and opening the Excel file separately. The solution is: (Program fragment)
String as = "I see. xls";
String fileName = as;//= Java.net.URLEncoder.encode (AS, "UTF-8");
/* Depending on the locale of the request, the Chinese operating system is usually gb2312 */
FileName = new String (as.getbytes ("GB2312"), "iso_8859_1");
as = FileName;
Response.setcontenttype ("application/vnd.ms-excel");
Response.setheader ("Content-disposition", "attachment; Filename= "+ AS
+ "");
Bufferedinputstream bis = null;
Bufferedoutputstream BOS = NULL;
try {
bis = new Bufferedinputstream (new
FileInputStream (Getservletcontext (). Getrealpath ("" + filename));
bis = new Bufferedinputstream (new FileInputStream (Dirfile));
BOS = new Bufferedoutputstream (Response.getoutputstream ());
byte[] buff = new byte[2048];
int bytesread;
while ( -1! = (bytesread = bis.read (buff, 0, buff.length))) {
Bos.write (Buff, 0, bytesread);
}
} catch (Final IOException e) {
System.out.println ("appears ioexception." + e);
} finally {
if (bis! = null)
Bis.close ();
if (BOS! = NULL)
Bos.close ();
}
The most critical sentence in the program section:
New String (As.getbytes ("GB2312"), "iso_8859_1");
Rename the file to transcode. Ok the result is normal >>>
This can be downloaded with the Chinese name, and is another open Excel file.
File Download: "Content-disposition", "attachment; Filename= Chinese name >>> solution