在 Linux 机器上遇到编码问题,而不是在 Windows 上
我遇到了一个编码问题,这个问题困扰了我几个星期,但似乎没有任何效果。我有一个网站在我的本地计算机上运行良好,但是当我将 jsp 文件推送到 Linux 机器进行审查时,以前呈现良好的字符现在显示为时髦的字符。
由于某种原因,某些字符显示得很好,但其他字符将无法正确编码。页面上的所有文本都从 java .properties 文件中读取,并使用 beans 输出到页面。
我在页面中添加了一个元标记来设置编码,但没有执行任何操作。我还添加了 <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>但这对 Linux 机器没有任何作用,实际上使编码错误出现在我的本地 Windows 机器上。
任何帮助将不胜感激。
I'm running into an encoding issue that has stumped me for a few weeks and nothing seems to work. I have a website that works fine on my local machine, but when I push the jsp files to a Linux box for review, characters that previously rendered fine are now displaying as funky characters.
For some reason, some characters display just fine, but other characters will not encode properly. All text on the page is being read from java .properties files and output to the page using beans.
I've added a meta tag to the page to set encoding, which did nothing. I also added <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> but this did nothing on the linux box and actually made the encoding errors appear on my local windows machine.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查加载属性的方法是否使用实际写入属性文件的字符编码。
如果没有显式设置,则使用文件系统的默认编码,在 Windows 上为 ISO-Latin-1,在 Windows 上为 ISO-Latin-1,在 Windows 上为 ISO-Latin-1。 8 在某些 Linux 发行版上。
Check that the method loading the properties is using the character encoding that the property files are actually written in.
Without explicit setting this, the default encoding for the file system is used, and it is ISO-Latin-1 on Windows, and UTF-8 on some Linux distributions.
为了使字符编码在 Nixes 和 Nuxes 中正常工作,需要配合使用以下内容:
通过页面指令,您只解决了最后一个项目符号。换句话说,您指示浏览器将页面解码为 UTF-8,但这不是您要发送的内容。
看看这篇(确实有几年历史的)论文,特别是第 11 章。
The following need to play together for character encoding to work properly in Nixes and Nuxes:
With your page directive, you only addressed the last bullet. In other words, you are instructing the brower to decode the page as UTF-8, but that's not what you are sending.
Take a look at this (admittedly a few years old) paper, chapter 11 in particular.
另外,检查两台机器上的物理文件。我见过一些 FTP 客户端在传输过程中弄乱了文件。快速检查是将文件作为 html 而不是 jsp 推送。所有
<% %>
序列都会出现垃圾,但其他文本应该显示不变。您还把应用程序服务器排除在外。如果文本仍然很奇怪,则表明您的 FTP 或 WebDAV 客户端正在尝试“提供帮助”。Also, check the physical files on both machines. I've seen several FTP clients muck up files during transfer. A quick check is to push your file as html instead of jsp. You'll get garbage for all the
<% %>
sequences, but the other text should show up unchanged. You've also taken the app server out of the equation. If the text is still funky, it's your FTP or WebDAV client trying to "help".查看服务器发送的http标头。这是浏览器首先查找编码的地方。
Look at the http headers sent by the server. That is the first place the browser looks for encoding before anything else.