setCharacterEncoding
void setCharacterEncoding(java.lang.String charset)
- Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the character encoding has already been set by
setContentType(java.lang.String)
orsetLocale(java.util.Locale)
,
this method overrides it. CallingsetContentType(java.lang.String)
with theString
oftext/html
and
calling this method with theString
ofUTF-8
is
equivalent with callingsetContentType
with theString
oftext/html;
.
charset=UTF-8This method can be called repeatedly to change the character encoding. This method has no effect if it is called after
getWriter
has
been called or after the response has been committed.上面是api的内容:
用法:setCharacterEncoding("UTF-8");
上述api的基本翻译如下:
给准备要发送到服务端响应对象response数据的MIME字符集编码进行设置,举个例子 UTF-8
如果setCharacterEnconding方法已经设置,会覆盖另外两种方法的设置。
setContentType("String
oftext/html;
charset=UTF-8");上面的解释道这两种设置方式是等价的。
另外如果这个方法在getWriter方法之后设置,或者在response对象已经提交之后设置,此方法就失效了。
servlet 发送到客户端的数据编码设置
时间: 2024-11-13 19:52:18