é变成&195;#169,然后变成é如何解决这个编码问题?
我在 Eclipse 中有一个 UTF-8 格式的 java 文件,并且有一些包含重音符号的字符串。
在 java 文件本身中,重音被写入并保存为 é 。 在使用速度生成的 xml 中,é 变为 é
在使用 fop 和 xsl 模板生成的 pdf 中,输出显示为 é
因此,这可能是一个编码问题,所有内容都应该采用 UTF-8。奇怪的是,在我本地运行应用程序的 Eclipse 环境(Windows)中,整个过程有效,并且正确的重音 é 显示在 pdf 中。
但是,当使用 Maven 构建应用程序并将其部署到(unix 环境)时,我看到了上述问题。
I have a java file in Eclipse that is in UTF-8 and has some strings containing accents.
In the java file itself, the accent is written and saved as é .
In the xml that is generated using velocity the é becomes é
In the pdf that is generated using fop and and an xsl template, the output is displayed as é
So this is probably an encoding issue and everything should be in UTF-8. What's weird is that locally in my eclipse environment (windows) where I run the application, the whole process works and the correct accents é are displayed in the pdf.
However when the application is built with maven and deployed to a (unix environment) I see the problem described above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许 Eclipse 使用与 Maven 不同的
javac
命令行来编译该文件。当你编译Java时,你必须告诉编译器源文件的编码(如果它们包含非ASCII字符并且默认不起作用)。
我认为在 Maven 中解决此问题的方法是将其添加到您的 pom.xml 文件中:(
我从 关于稍微不同的问题的 Maven 常见问题解答。)
您可以通过在 Java 文件中使用丑陋的 Unicode 转义序列来完全避免编码问题。
é
将变为\u00e9
。对人类来说更糟糕,对烤面包机来说更容易。 (正如玻璃市所说,“在人机共生中,必须由人来调整:机器却不能。”)Perhaps Eclipse is compiling the file with a different
javac
command line than Maven.When you compile Java, you have to tell the compiler the encoding of the source files (if they contain non-ASCII characters and the default doesn't work).
I think the way to fix this in Maven is to add this to your pom.xml file:
(I got that from a Maven FAQ about a slightly different issue.)
You could instead avoid the encoding issue entirely by using ugly Unicode escape sequences in your Java file.
é
would become\u00e9
. Worse for humans, easier for the toasters. (As Perlis said, "In man-machine symbiosis, it is man who must adjust: The machines can't.")