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

本文详细介绍了如何在HTTP请求和响应中设置MIME类型与编码,包括请求体和响应正文的编码设置方法及作用。

    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", 也就是只针对请求体, 不是请求头.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值