我从其他开发人员那里得到了一些 jsp 文件,现在需要使用它们。当我向文档添加任何 UTF-8 字符并想要保存文档时,NetBeans 会自动为我提供 ISO-8859-1 格式的保存。
实际上我从 NetBeans 收到了这条消息:
The index.jsp contains characters which will probably be damaged during conversion to the ISO-8859-1 character set. Do you want to save the file using this character set? (Yes/No)
NB 没有提供任何其他选项,比如将文件保存为 UTF-8(因为它应该已经写入)。
我不知道如何将那些 jsp 文件保存在它们已经写入的字符集中。
不要告诉我,更改文件本身的内容(由于包含来自其他文件的标题等而无效)是唯一的方法...
最佳答案
首先;不要忘记在顶部考虑这一行:
<%@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 开始,您还可以指定将在运行时使用的编码。例如,当运行应用程序的操作系统的编码与项目的编码不同时,这会很有用。
指定要在运行时使用的编码:
- 在项目的"file"窗口中,打开 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.
这些可能对你有帮助。
我使用的答案来源:
关于java - 在 NetBeans 中将 JSP 保存为 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4900157/