Reputation: 13
I have a richfaces page where you can export the contents of a data table to a csv, xls, xml or pdf file. I am facing an issue with exporting Japanese characters.
Characters such as テスト商品 appear in the exported file(all formats) as テスト商品
However other characters such as Tシャツ are displayed correctly. The application is deployed on tomcat and websphere, this issue only happens on the websphere instance.
I tried adding -Dclient.encoding.override=UTF-8 for Generic JVM Arguments on websphere, but that didn't solve the issue. I also tried changing the encoding for the Japanese language to UTF-8 in the encoding.properties file, but that didn't solve it either.
This is an example of the java code used to export to csv:
//response in an HttpServletResponse
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-disposition","attachment; filename=workbook.csv");
StringBuffer txtBuffer = new StringBuffer();
ServletOutputStream out = response.getOutputStream();
DataExporter.getCSVWorkbook(lstToBeExported, txtBuffer);
byte[] bytes = txtBuffer.toString().getBytes("UTF-8");
out.write(bytes);
out.close();
Does anyone have an idea about why this works for some characters and not others, and why it works on tomcat but not websphere?
Upvotes: 1
Views: 991
Reputation: 13
I added a filter to encode the characters before they are transferred from the browser to the server, it solved the problem. The issue was that they were being wrongly encoded before get to the server.
Upvotes: 0