Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse JSP: incorrect default text file encoding

Tags:

eclipse

jsp

I've got the following problem. I created a new "Dynamic Web Project" and imported some existing jsp files into it.

If i right click one of the imported jsp files and click "Properties" > "Resource" then under the "Text file encoding" section a value of "Default (determined by content type: ISO-8859-1)". However i have runned iconv before importing to assure they're in utf-8:

$ iconv -f "ISO-8859-1" -t "UTF-8" from.jsp > to.jsp

All the jsp files has the following meta set:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Does anybody know how to change this setting? Tomcat is serving them correctly as utf-8 (http content-type header), so i don't really know in what this impacts...

like image 953
roirodriguez Avatar asked Jan 28 '12 13:01

roirodriguez


1 Answers

It's not a bug, it's a feature

Eclipse didn't "determine" the correct encoding by scanning the file as like file or iconv commands on your shell.

Solution: Add following line to your JSP:

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

This is a good Idea due to many Web-Container will force to deliver ISO-8859-1 encoded files nevertheless you have set the correct content type in your HTML Header.

FYI: Mismatching CharacterSets and file encodings will lead

  • to characters like in "Schei� encoding" (Latin1 character in UTF8 (multiByte) context).
  • If you got something like "für" it is indead a broken multibyte character (typically UTF-8) in a singleByte character context (Latin1 / ISO-8859-1 || ISO-8859-15 for Germans)
like image 169
childno͡.de Avatar answered Sep 27 '22 17:09

childno͡.de