Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF-8 Encoding name in downloaded file

I'm trying to let the user download the excel file with japanese name. It seems that it works IE 8 only and other IE and firefox, it is not working. Kindly suggest me how to hadndle this.

String fileName = dateString+"_マイページ情報.xls"; byte[] data = writer.getData(); response.setContentType("application/ms-excel"); response.setContentLength(data.length); response.setHeader("Expires:", "0"); // eliminates browser caching response.setHeader("Content-Disposition","attachment; filename="+URLEncoder.encode(fileName)); 
like image 1000
zawhtut Avatar asked Aug 05 '13 04:08

zawhtut


People also ask

How do you tell if a file is UTF-8 encoded?

Open the file in Notepad. Click 'Save As...'. In the 'Encoding:' combo box you will see the current file format. Yes, I opened the file in notepad and selected the UTF-8 format and saved it.

What are UTF-8 encoded files?

UTF-8 is an encoding system for Unicode. It can translate any Unicode character to a matching unique binary string, and can also translate the binary string back to a Unicode character. This is the meaning of “UTF”, or “Unicode Transformation Format.”

How do I find out if a csv file is UTF-8 encoded?

The evaluated encoding of the open file will display on the bottom bar, far right side. The encodings supported can be seen by going to Settings -> Preferences -> New Document/Default Directory and looking in the drop down.


1 Answers

I got it solved as the following.

fileName = dateString+"_マイページ情報.xls";  fileName = URLEncoder.encode(fileName,"UTF-8");  try {         response.setContentType("application/ms-excel; charset=UTF-8");         response.setCharacterEncoding("UTF-8");         if(browserType.equals("IE")||browserType.equals("Chrome"))             response.setHeader("Content-Disposition","attachment; filename="+fileName);         if(browserType.endsWith("Firefox"))             response.setHeader("Content-Disposition","attachment; filename*=UTF-8''"+fileName);     } catch (Exception e1) {         // TODO Auto-generated catch block         e1.printStackTrace();     } 
like image 94
zawhtut Avatar answered Oct 14 '22 02:10

zawhtut