Search code examples
xpages

how to set the response writer in XPages to UTF-8?


I have a Porblem an I hope that someone could help me.

I'm reading some values from an notes View by using the following Code

...
ViewEntryCollection vec = MyView.getAllEntries();
ViewEntry viewentry = vec.getFirstEntry();
while (viewentry != null) {
     row = new Vector<String>();
 Vector rowvec = viewentry.getColumnValues();
...

then I build an HTML table with the values this works fine my Problem is the the Response to an Xpage

public void getHTMLStream(DominoFacesContext FacesContext, String HTMLstr) {
     ExternalContext con = FacesContext.getExternalContext();
     XspHttpServletResponse response = (XspHttpServletResponse)    
     con.getResponse();
     byte[] content;
     try {
          ServletOutputStream writer = response.getOutputStream();

      // setting response headers for browser
      response.setContentType("application/html");
      response.setHeader("Cache-Control", "no-cache");
      response.setHeader("Content-Disposition", "attachment; filename=\"myhtml.html\"");

          content = HTMLstr.getBytes();
      writer.write(content);

      writer.flush();
      writer.close();

      FacesContext.responseComplete();
    } catch (Exception e) {
       e.printStackTrace();
    }
}

If in the HTMLstr are German Umlauts like ä,Ö,Ü the "writer" converts them to some stange signs. Has anyone an idea how to solve this?

Christian


Solution

  • you can set charset in the contenttype by the following statement

    response.setContentType("application/html;charset=UTF-8");