栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

码头响应字符编码

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

码头响应字符编码

Jetty文档声称它默认情况下使用UTF-8,但这似乎是一个谎言。如果执行normal

response.getWrite().println("Hello")
,则内容编码如下确定。

  1. 从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
  1. 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。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570718.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号