简体   繁体   中英

CSV generated by Java-Servlet: Encoding always “undefined”

I am creating a CSV-File in my Java-Servlet.

I am setting everything to UTF-8:

response.setContentType("text/csv;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=\"shippingInfosForDHLImport.csv\"");

If I access my servlet in the browser and download the file, special cases are broken and if I open the file in sublime and type: "view.encoding()" to the console it shows me:

"u'Undefined'"

The servlet is running on google app engine and I am downloading the file to a Mac.

If I run the servlet locally. Everything works fine and the encoding in sublime is shown as UTF-8 (even if I remove the UTF-8 settings in my code).

How can I get the encoding for the file right, if the code is running on App engine? Is there another config param I can set?

I solved the Problem by writing my CSV content to the PrintWriter:

response.getWriter().write(result);

instead of to the OutputStream:

response.getOutputStream().write(result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM