2

I want to export csv file from XPages, and want set the character encoding "shift-jis",not "utf-8".(Because MS Excel treats csv file encoding as OS default.In the case of Japanese OS, it's Shift-JIS.)

My Code is below.

var exCon:com.ibm.xsp.domino.context.DominoExternalContext = facesContext.getExternalContext();
var writer:com.sun.faces.renderkit.html_basic.HtmlResponseWriter = facesContext.getResponseWriter();
var response:com.ibm.xsp.webapp.XspHttpServletResponse = exCon.getResponse();
response.setContentType("Content-type:application/octet-stream; charset=Shift_JIS");
response.setHeader("Cache-Control", "no-cache");
writer.write("あいうえお");
writer.write("かきくけこ");

HtmlResponseWriter Object has getCharacterEncoding() method. But it doesn't have "setCharacterEncoding()" method. Is there any way to change character encoding?

Thanks in advance!

Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76
satohiro
  • 267
  • 1
  • 10
  • "Application Properties->XPages->HTML Generation->Encode->Shit_jis" – satohiro Oct 01 '12 at 02:02
  • It seems that changing Application property like "Application Properties->XPages->HTML Generation->Encode->shift_jis" can be solution for this.But it wiil change entire application html, so we should check side effect for this change. – satohiro Oct 01 '12 at 02:06

1 Answers1

1

You need to set character encoding on the servlet response.

In your case:

response.setCharacterEncoding("shift-jis");
Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76
  • Thank you so much for your quick Response, Henrik. – satohiro Sep 04 '12 at 01:32
  • I add 「response.setCharacterEncoding("shift-jis");」, but even then it doesn't seem to work. I don't know why... Fredrik Stöckel seemed to say same thing, here. http://www.wissel.net/blog/d6plinks/SHWL-7MGFBN – satohiro Sep 04 '12 at 01:39
  • In my simple test I could see in Chrome Developer Tools that character encoding was specified. Let me try again. – Per Henrik Lausten Sep 04 '12 at 04:24
  • 1
    The encoding of the response stream is changed by the setting, but not the encoding of the file. I think that the only way is to create a file, add the content and send it back to browser with content-type-encoding header f.e. base64 encoded. The file has to be base64 encoded too. – Sven Hasselbach Sep 04 '12 at 05:38
  • Thanks for the clarification, Sven. I suggest that you add an answer with these details – Per Henrik Lausten Sep 04 '12 at 07:39
  • Thanks,Sven,Henrik.I have understood this behavior. And I also hope you add an answer here,Sven. That would help other developers, not only me. – satohiro Sep 05 '12 at 02:01