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.
Looks like you are just missing the pageEncoding attribute.
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
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.
Related
so i am a bit stucked on this and i am also a bit lost. I have a GWT App and all .java files and everything is encoded in cp1250 (as default, from container) i tried to change encoding at my .html (because everything was in UTF-8)
<meta http-equiv="content-type" content="text/html; charset=cp1250">
and also web.xml file,appengine-web.xml file and .gwt.xml file
<?xml version="1.0" encoding="utf-8"?>
to cp1250 but i cant get the encoding right, i need to display and store characters like áéžčťíóšľĺ... i also tried to change encoding of some .java files to ISO--8859-1 as well as in the .html and .xml files but nothing worked. I dont know EXACTLY what to change, so maybe thats my problem.
I use RPCs for text(String) transfer so i can get those characters from input to server side and write them with println() correctly, but i cant save them to datastore correctly.
So, is there a way to store such characters or show them in Labels etc. ? If yes, what should i do exactly ? Or storing in datastore and showing them only in com.google.gwt.user.client.ui.HTML would be sufficient as well, thanks a lot for your time.
SOLUTION
Ok so basicaly what i was doing wrong was that default cp1250 enxoding. Just set the encoding on everything to UTF-8 and displaying and storing will be just fine, it will convert some of special characters in your code to "?" when u change it, but with a little bit of extra work you can change it back.
Sorry for the dumb question, but i though UTF-8 wasnt way to go... idk why :P
what type of encoding or what do I have to do to make my web site display properly the text with German characters like this: Käse and not like this: K�se ?
Here is what I use for doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
and here is what I use for encoding:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
the collation in mysql that I use is utf8_general_ci, I have never done web sites with other languages except for english (from scratch). I dont know what I am missing!
Thank you for your time!
Your encoding choise looks fine.
There is just two steps left: You have to make sure that the content type in the HTTP header also says the same, and you have to make sure that what you actually send is encoded using UTF-8.
UTF-8 should used for sites that cater for many languages, so is suitable for your needs.
The meta tag is correct too, though you may want to ensure that the server is sending the right Content-Type header.
Ensure that the HTML file is also encoded with UTF-8 and not ASCII or another codepage.
In general, you need to ensure that all steps from the DB to the browser use UTF-8 (so, DB columns are UTF-8, transferred to the server as UTF-8, rendered as UTF-8, transferred to the browser as UTF-8 with the right headers and meta tags).
From my expiriense, for utf-8 to work right:
MySql data needs to be in some of the "utf-8" collations
The meta tag needs to define charset as "utf-8"
The MySql connector needs to be set to "utf-8" (for php, its mysql_set_charset)
The server-side file (*.php or the like) needs to be saved in utf-8 (not actually necesary, but it saves some pain)
I having a hard trying to properly display Vietnamese text in ColdFusion. I've proper charset set to UTF-8 but still no luck. The same texts work fine in a HTML page. What else am I missing? Any suggestion would be much appreciated.
Html:
ColdFusion:
Thanks!
There are two things you need to watch out for, as far as I recall of the top of my head.
The first is to ensure that the .cfm file itself is saved as UTF-8 - this is a file system option, and will probably be settable in your editor. This ensures that the UTF-8 characters are correctly preserved when saving the file.
The other is that every .cfm file that includes any UTF-8 text should start with:
<cfprocessingdirective pageencoding="utf-8" />
This ensures that ColdFusion delivers the page to the browser in the correct format.
Just to be sure, when you display your working HTML, can you check the page encoding used by your browser (ie. in FireFox you can right-click+page Info). Maybe your text is not UTF-8 encoded that could explain the problem...
Is there any restrictions for it to show normally?
Sounds like an encoding problem. For special characters like that, I prefer to use HTML entities. In this case, try »
After my experience, a question mark usually replaces undecodable special characters when you encode your special characters with utf8, because web browsers by default decode the web page using iso-latin1. You can/should explicitely declare the encoding of your web page using the following directive:
<?xml version="1.0" encoding="UTF-8" ?>
for xhtml, or
<meta http-equiv="Content-Type" content="text/html"; charset="utf-8">
(inside the element), for HTML.
Regard this post as a supplement, because I guess that using the xml/html entities like » or » mentioned above are the better way to go.
You can also use »
If your Apache server is configured with...
AddDefaultCharset UTF-8
...in the httpd.conf file (which, strangely, was the default on my server), then Content-Type specs in the .html files (e.g., <meta http-equiv=Content-Type content="text/html; charset=windows-1252">) will be ignored, causing character codes above 127 to be interpreted incorrectly.
Comment out the AddDefaultCharset line and restart Apache.
The iPhone app I'm working on uses html help files and special characters such as
ü and ê
are being mangled my iPhone's mobile Safari. Anything I can do to correct this?
If you're using XHTML, ensure that the content of your files really is the encoding specified in the doctype. If you're using just plain HTML, consider using XHTML instead, or
Use HTML entities (e.g. é)
Use the META tag to specify an encoding
Have you tried using numerical character references? Alternatively, perhaps you can use a <meta http-equiv="content-type" ... element. Also, maybe there's a better way to tell mobile Safari the character encoding of HTML files (equivalent to the server's HTTP Content-Type header)