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

request和response编码

时间:2018-05-02 13:14:57      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:char   head   coding   nbsp   character   传参数   color   ram   eth   

response:默认使用iso-8859-1编码进行编码传送数据给客户端。

服务器设置编码使用:setCharacterEncoding("uft-8");
告知浏览器解码格式:setheader("content-type","text/html;charset=utf-8")
两者可以简化为:setcontentType("text/html;charset=utf-8")
*****response中响应头中的参数,浏览器默认使用gbk解码。上述方式无效
 例如:response.addHeader("Content-Disposition", "attachment;filename="filename");
filename需要转码成gbk编码。 byte[] b = filename.getBytes("gbk2313");
filename = new string(b); 
 
 
request:在地址栏中直接传参数默认使用UTF-8
其它方式提交数据,默认使用当前面页使用的编码格式。
服务器指定编码解码:
服务器对于post方式,可以使用request.setCharacterEncording("utf-8")方式指定解码方式为utf-8
对于get方式,只能使用字符转码。new String(request.getparam("name").getBytes("iso-8859-1"),"utf-8")

request和response编码

标签:char   head   coding   nbsp   character   传参数   color   ram   eth   

原文地址:https://www.cnblogs.com/sxf2086he/p/8979363.html

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