在NetBeans中将JSP保存为UTF-8
我有一些来自其他开发人员的jsp文件,现在需要使用它们。 当我向文档中添加任何UTF-8字符并想要保存文档时,NetBeans会自动为我保存ISO-8859-1。
实际上我从NetBeans收到此消息:
index.jsp包含在转换为ISO-8859-1字符集时可能会损坏的字符。 是否要使用此字符集保存文件? (是/否)
NB没有提供任何其他选项,比如将文件保存为UTF-8(因为它应该已经写入)。
我不知道如何将这些jsp文件保存在已经写入的字符集中。
并且不要告诉我,改变文件本身的内容(由于包含来自其他文件的标题等而无效)是唯一的方法……
http://forums.netbeans.org/topic8750.html
首先; 不要忘记在顶部考虑这条线:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
其次; 在NetBeans文件夹中有一个配置文件。 应该有这样一条线:
netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true"
将其添加到该行的末尾:
-J-Dfile.encoding=UTF-8
第三:
NetBeans实现项目编码设置。
要更改项目的语言编码:
- 在“项目”窗口中右键单击项目节点,然后选择“属性”。
- 在“源”下,从“编码”下拉字段中选择一个编码值。
编码至少影响:
* how non-ASCII characters are displayed in the editor window when you open files * Java file compilation of sources containing non-ASCII identifiers, string literals, or comments * textual search for international characters over the project
从NetBeans IDE 6.8开始,您还可以指定将在运行时使用的编码。 例如,当运行应用程序的操作系统的编码与项目的编码不同时,这可能很有用。
要指定要在运行时使用的编码:
- 在项目的“文件”窗口中,打开nbproject> private> private.properties
- 将以下行添加到private.properties文件并保存更改:
runtime.encoding =
此编码将覆盖项目的编码设置,并在运行应用程序时使用。
一般来说,
*.properties files always use ISO-8859-1 encoding plus \uXXXX escapes. (International characters will be displayed natively in the editor but stored as an escape on disk.) *.xml files and some *.html files can specify their own encodings, regardless of the project encoding. For such files, the IDE's editor ignores the project encoding.
这些可能对你有帮助。
我使用的答案来源:
Link1: http : //forums.netbeans.org/topic33.html
Link2: http ://wiki.netbeans.org/FaqI18nProjectEncoding