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.
Related articles
Related CZ Podcast episodes
- #217 · Ivo Lukačovič
On Windy, JavaScript and building companies. · Czech audio
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio