Eclipse JSP:不正确的默认文本文件编码 [英] Eclipse JSP: incorrect default text file encoding
问题描述
我遇到以下问题。我创建了一个新的动态Web项目,并将一些现有的jsp文件导入到其中。
I've got the following problem. I created a new "Dynamic Web Project" and imported some existing jsp files into it.
如果我右键单击一个导入的jsp文件,然后单击属性>资源,然后在文本文件编码部分下的值Default按内容类型:ISO-8859-1)。然而,在导入之前,我已经运行iconv,以确保他们在utf-8:
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
所有的jsp文件都有以下元集:
All the jsp files has the following meta set:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
有人知道如何更改此设置? Tomcat正是以utf-8(http内容类型头文件)正确的方式提供服务,所以我不太了解这些影响...
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...
推荐答案
这不是一个bug,它是一个功能
It's not a bug, it's a feature
Eclipse没有通过像文件或iconv命令一样扫描文件来确定正确的编码您的shell。
Eclipse didn't "determine" the correct encoding by scanning the file as like file or iconv commands on your shell.
解决方案:在JSP中添加以下行:
Solution: Add following line to your JSP:
<%@ page pageEncoding="UTF-8" %>
这是一个很好的想法,由于许多Web-Container将强制提供ISO-8859-1编码文件,但您在HTML标题中设置了正确的内容类型。
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:不匹配的CharacterSet和文件编码将导致
- 到Schei 编码(UTF8(multiByte)上下文中的拉丁字符))中的字符。
- 如果得到类似fÃrr的东西,它在单字符字符上下文(Latin1 / ISO-8859-1 || ISO-8859-15)中是一个破碎的多字节字符(通常为UTF-8)。
这篇关于Eclipse JSP:不正确的默认文本文件编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!