Grails - 将HTML文件作为UTF-8提供? [英] Grails - serve HTML files as UTF-8?
问题描述
UTF-8在通过/ web-app通过tomcat提供的.html文件中被破坏。如果我用 file:///
直接打开文件,它会呈现正常。如果我在运行应用程序中查看文件,它看起来很好。但是,当我作为战争部署时,UTF-8字符显示为乱码。
UTF-8 is broken on .html files served through tomcat through /web-app. If I open the file directly with file:///
, it renders fine. If I view the file during run-app, it looks fine. However, when I'm deployed as a war, UTF-8 characters appear garbled.
响应的内容类型似乎正确...
Content-Type:text / html; charset = UTF-8
,HTML文件本身似乎也有正确的元声明。
The content-type of the response seems correct...
Content-Type: text/html;charset=UTF-8
, and the HTML file itself even seems to have the correct meta declarations.
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
对于默认的URIEncoding,Tomcat的连接器设置为UTF-8,所以我认为这也不是问题。 GSP呈现良好;只有HTML文件有问题。
Tomcat's connector is set to "UTF-8" for default URIEncoding, so I don't think that's the issue either. GSPs are rendering fine; only the HTML file has an issue.
这里可能会发生什么情况?
What could be going on here?
编辑:
使用firefox,我保存了原始HTML文件的本地副本,并直接从 file:/// ...
中读取文件进行比较。这两个文件之间的区别仅在于Tomcat版本将所有非ascii字符替换为:
Using firefox, I saved a local copy of the raw HTML file and the file read directly from file:///...
for comparison. The only difference between the files is that the Tomcat version has all non-ascii characters replaced with this:
�
根据您使用的编辑器将其渲染为空白方形或问号。该字符本身似乎是 EF BF BD
,它将替换所有非ASCII字符。不知何故,在提供文件时,tomcat或grails只是跺脚unicode字节。什么可以做那?
Which either renders as an empty square or question mark depending on what editor you're using. The character itself seems to be EF BF BD
, which replaces all the non-ascii characters. Somehow, in serving a file, tomcat or grails is just stomping on the unicode bytes. What could do that?
编辑编辑:
即使这 w3测试文件与我的文件具有相同的行为,表明我的文件可能没有问题,Tomcat / Grails确实存在一些问题。
EDIT Even this w3 test file has the same behavior as my files, indicating that my files are probably fine, and there really is something up with Tomcat/Grails.
Grails 1.3.7至少不能正确提供HTML文件。编写你自己的文件服务器控制器。
Grails 1.3.7, at least, cannot serve HTML files correctly. Write your own file server controller.
这篇关于Grails - 将HTML文件作为UTF-8提供?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!