码迷,mamicode.com
首页 > 其他好文 > 详细

servlet 发送到客户端的数据编码设置

时间:2014-05-15 01:36:58      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:servlet编码设置   setcharacterencoding   setcontexttype   

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) or setLocale(java.util.Locale), this method overrides it. Calling setContentType(java.lang.String) with the String of text/html and calling this method with the String of UTF-8 is equivalent with calling setContentType with the String of text/html; charset=UTF-8.

This 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 of text/html; charset=UTF-8");

上面的解释道这两种设置方式是等价的。

另外如果这个方法在getWriter方法之后设置,或者在response对象已经提交之后设置,此方法就失效了。

servlet 发送到客户端的数据编码设置,布布扣,bubuko.com

servlet 发送到客户端的数据编码设置

标签:servlet编码设置   setcharacterencoding   setcontexttype   

原文地址:http://blog.csdn.net/hymking/article/details/25834707

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!