oligofren
oligofren

Reputation: 22923

Rendered JSP markup has garbled UTF-8 characters

I modified the embedded-jetty project to create a stand-alone jsp-viewer (one file with full source code). The result works fine, but it has a problem in displaying JSPs containing special glyphs. The problem is not that the Content-Type is not set when transmitting the markup, but that the rendered markup is garbled (in view-source or via curl). The JSP files must be read using the wrong character encoding, but starting the jvm with -Dfile.encoding=UTF-8 does nothing.

These strings

Butikknavn – et smartere valg
få ekstra fordeler når

becomes

Butikknavn â<80><93> et smartere valg
få ekstra fordeler når

Edit: Just to state the obvious, the content header is already set, as can be seen from the raw HTTP response

Content-Type:text/html;charset=utf-8

Upvotes: 1

Views: 408

Answers (2)

Jozef Chocholacek
Jozef Chocholacek

Reputation: 2924

You have to add

<%@ page pageEncoding="UTF-8" %>

to your JSP file(s).

The -Dfile.encoding=UTF-8 should do the pageEncoding="UTF-8" part for the whole Jetty instance, regrettably, as you've mentioned, it doesn't. You might also try to add <page-encoding>UTF-8</page-encoding> to your web.xml (as described here), but I've never tried it.

Upvotes: 1

Guy Bouallet
Guy Bouallet

Reputation: 2125

Your HTTP response is probably missing the content-type header. Try adding one as follows:

Content-Type: text/html; charset=utf-8

Upvotes: 0

Related Questions