Question

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

Was it helpful?

Solution

you can set charset in the contenttype by the following statement

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

OTHER TIPS

Another options would be to just use the correct method

response.setCharacterEncoding()

Try this:

content = java.net.URLEncoder.encode(content,"UTF-8");

In case anyone still needs this. PrintWriter uses Encoding from xsp properties, so just make sure you have xsp.html.page.encoding=utf-8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top