
Jetty文档声称它默认情况下使用UTF-8,但这似乎是一个谎言。如果执行normal
response.getWrite().println("Hello"),则内容编码如下确定。- 从content-type到content-encoding的默认映射是从加载的
org/eclipse/jetty/http/encoding.properties
:// MimeTypes.java:155 ResourceBundle encoding = ResourceBundle.getBundle("org/eclipse/jetty/http/encoding"); Enumeration<String> i = encoding.getKeys(); while(i.hasMoreElements()) { String type = i.nextElement(); __encodings.put(type,encoding.getString(type)); }
默认文件是:
text/html = ISO-8859-1text/plain = ISO-8859-1text/xml = UTF-8text/json = UTF-8
Response.getWriter()
尝试使用该地图,但默认为ISO-8859-1@Override
public PrintWriter getWriter() throws IOException
{
if (_outputType == OutputType.STREAM)
throw new IllegalStateException(“STREAM”);if (_outputType == OutputType.NONE){ String encoding = _characterEncoding; if (encoding == null) { encoding = MimeTypes.inferCharsetFromContentType(_contentType); if (encoding == null) encoding = StringUtil.__ISO_8859_1; setCharacterEncoding(encoding); }
因此,您可以看到
text/html它并非默认为UTF-8。我认为没有办法从代码中更改默认值。最好的办法是将
encoding.properties文件更改为此:
text/html = UTF-8text/plain = UTF-8text/xml = UTF-8text/json = UTF-8
但是即使这样,即使找到的编码也不存在,它也会默认为ISO-8859-1。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)