Reputation: 51
I have a problem with encoding and Jetty.
All my files are encoded in UTF-8 and include the correct HTML meta tag to specify UTF-8.
Until now all my UTF-8 files had a BOM and I had no problem. But now I am using a different text editor and I noticed that my UTF-8 files are now generated without a BOM which from what I read is rather a good thing so I decided to go without BOM from now.
But the problem is that it seems that Jetty converts all my JSP files to ISO8859-1 before sending them to the browser if they don't have a BOM. It causes problem because since they have a meta tag for UTF-8 the browser interprets the files as UTF-8 and accents and other special characters do not work.
I found one workaround so far which is to start all my JSP files with :
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
This works but it is kindof annoying because I have to add this at the start of every file and I would rather have some server wide parameter to avoid that, if it is possible, but as I spent hours browsing the web for a solution I am beginning to think there is none.
I tried to add
JAVA_OPTIONS+=("-Dfile.encoding=UTF-8")
to my JAVA_OPTIONS when starting jetty as suggested in an other thread but it doesn't seem to do anything.
Any help would be greatly appreciated.
Upvotes: 2
Views: 4321
Reputation: 21
Another option that worked for me in the case of handling UTF-8 encoded files on Jetty was to change the webdefault.xml content to support UTF-8 encoding instead of the default ISO-8859-1.
You can find this file in the {{JETTY_HOME}}/etc/webdefault.xml
<locale-encoding-mapping>
<locale>en</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
Hope this helps.
Upvotes: 1
Reputation: 49452
Looks like you are just missing the pageEncoding
attribute.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
Upvotes: 2