如何解决此编码问题

如何解决此编码问题

本文介绍了é变成& 195;#169,然后变成é如何解决此编码问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse中有一个Java文件,其格式为UTF-8,其中包含一些包含重音符号的字符串.

I have a java file in Eclipse that is in UTF-8 and has some strings containing accents.

在java文件本身中,重音被编写并保存为é.在使用速度生成的xml中,é变为é在使用fop和xsl模板生成的pdf中,输出显示为é

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 é

因此,这可能是编码问题,所有内容都应使用UTF-8.奇怪的是,在我运行应用程序的日食环境(Windows)中,整个过程正常进行,并且正确的重音é显示在pdf中.

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.

但是,当使用maven构建应用程序并将其部署到(unix环境)时,我看到了上述问题.

However when the application is built with maven and deployed to a (unix environment) I see the problem described above.

推荐答案

也许Eclipse正在使用与Maven不同的javac命令行来编译文件.

Perhaps Eclipse is compiling the file with a different javac command line than Maven.

编译Java时,必须告诉编译器源文件的编码(如果它们包含非ASCII字符,并且默认设置不起作用).

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).

javac -encoding utf8 MyCode.java

认为在Maven中解决此问题的方法是将其添加到您的pom.xml文件中:

I think the way to fix this in Maven is to add this to your pom.xml file:

<project>
  ...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  ...
</project>

(我是从关于一个稍微不同的问题的Maven常见问题解答中获得的. )

您可以通过在Java文件中使用丑陋的Unicode转义序列来完全避免编码问题. é将成为\u00e9.对人类来说更糟,对烤面包机来说更容易. (正如Perlis所说,在人机共生中,必须由人来调整:机器不能."

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.")

这篇关于é变成&amp; 195;#169,然后变成é如何解决此编码问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:04