dagblog.
← Archive

Tomcat and the Encoding of External Files


Yesterday I ran into an encoding problem with external files, specifically JavaScript. Both the JavaScript and the page it was part of used UTF-8. Unfortunately, the Tomcat web server serves external parts of a page in ISO-8859–1 by default.

Fortunately, I found a fairly elegant fix in the server configuration. Servlet configuration lets you define MIME type mappings, so I just had to open the familiar web.xml in %TOMCAT_HOME%/conf and find the following line:

js 
text/javascript

Then add the encoding information, which the web server sends in the HTTP response header.

js 
text/javascript; charset="utf-8"

Thanks are also due to IEWatch, which made it very easy for Nkd and me to inspect the headers.

Medium version

Related articles

Related CZ Podcast episodes