web基础(get和post提交乱码问题)

get和post提交方式乱码问题:

(1)post提交:

request.setCharacterEncoding("UTF-8");

直接告诉服务器编码的格式。

(2)get提交:

采用request.setCharacterEncoding("UTF-8");的方法已经不能解决中文乱码的问题了。需要从底层改变编码格式:

name = new String(name,getBytes("ISO-8859-1"),"UTF-8");

 post提交的请求在请求体中,可以通过设置编码解决乱码。而get提交的数据在请求行中,通过设置编码的方式是不行的。

 

posted @ 2020-03-13 22:22  怀梦想,致远方  阅读(169)  评论(0编辑  收藏  举报