码头9,字符编码UTF-8 [英] Jetty 9, character encoding UTF-8
问题描述
我在编码和Jetty方面有问题.
I have a problem with encoding and Jetty.
我的所有文件都以UTF-8编码,并包含正确的HTML元标记以指定UTF-8.
All my files are encoded in UTF-8 and include the correct HTML meta tag to specify UTF-8.
直到现在,我所有的UTF-8文件都具有BOM,并且我没有任何问题.但是现在我使用的是不同的文本编辑器,我注意到生成的UTF-8文件现在没有BOM,从我的阅读来看这是一件好事,所以我决定从现在开始不使用BOM.
Until now all my UTF-8 files had a BOM and I had no problem. But now I am using a different text editor and I noticed that my UTF-8 files are now generated without a BOM which from what I read is rather a good thing so I decided to go without BOM from now.
但是问题是,如果Jetty没有BOM表,那么在将我的所有JSP文件发送到浏览器之前,它们似乎都已转换为ISO8859-1.引起问题的原因是,由于它们具有UTF-8的元标记,因此浏览器会将文件解释为UTF-8,并且带重音符号和其他特殊字符无效.
But the problem is that it seems that Jetty converts all my JSP files to ISO8859-1 before sending them to the browser if they don't have a BOM. It causes problem because since they have a meta tag for UTF-8 the browser interprets the files as UTF-8 and accents and other special characters do not work.
到目前为止,我发现了一种解决方法是使用:p来启动我的所有JSP文件.
I found one workaround so far which is to start all my JSP files with :
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
这可行,但是有点烦人,因为我必须在每个文件的开始处添加它,并且我希望有一些服务器范围的参数来避免这种情况(如果可能的话),但是由于我花了数小时在Web上浏览了一个解决方案我开始认为没有.
This works but it is kindof annoying because I have to add this at the start of every file and I would rather have some server wide parameter to avoid that, if it is possible, but as I spent hours browsing the web for a solution I am beginning to think there is none.
我尝试添加
JAVA_OPTIONS+=("-Dfile.encoding=UTF-8")
在其他线程中建议启动码头时,进入我的JAVA_OPTIONS,但似乎没有任何作用.
to my JAVA_OPTIONS when starting jetty as suggested in an other thread but it doesn't seem to do anything.
任何帮助将不胜感激.
推荐答案
好像您只是缺少pageEncoding
属性.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
这篇关于码头9,字符编码UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!