Java EE 中的请求和响应编码问题 - 相关API汇总

来源:互联网 发布:python分布式读取 编辑:程序博客网 时间:2024/05/22 08:14

    request    setContentType        不存在
    request    getContentType        "获取请求正文的 MIME 类型. 如果未知, null"    (详解,API[1])
    request    setCharacterEncoding    覆写请求体的编码.    [2]
    request    getCharacterEncoding    获取请求体的的编码, 如未定义, null.    [3]
    //
    response    setContentType        "设置响应正文的 MIME 类型"    (详解)
    response    getContentType        "返回响应正文的 MIME 类型"    (详解)
    response    setCharacterEncoding    "设置响应正文的字符编码, 默认为 ISO-8859-1"    (详解)
    response    getCharacterEncoding    "返回响应正文的字符编码"    (详解)

    参考原文:
    [1]    String getContentType()
            Returns the MIME type of the body of the request, or null if the type is not known. For HTTP servlets, same as the value of the CGI variable CONTENT_TYPE.
            Returns:
                a String containing the name of the MIME type of the request, or null if the type is not known
    [2]    Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader(). Otherwise, it has no effect.
        "覆盖"请求体中的编码名称. 必须在读取参数和输入流之前设置, 否则无效.
    [3]    String getCharacterEncoding()
            Returns the name of the character encoding used in the body of this request. This method returns null if the request does not specify a character encoding
            Returns:
                a String containing the name of the character encoding, or null if the request does not specify a character encoding
    详解 : 孙卫琴《Tomcat 与 Java Web 开发技术详解》

    注意 : request 的3个 API 都写明了是"body of the request", 也就是只针对请求体, 不是请求头.

0 0
原创粉丝点击