当前位置: 移动技术网 > IT编程>开发语言>Java > jsp中 ajax的get请求的中文乱码问题的解决方法

jsp中 ajax的get请求的中文乱码问题的解决方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

一般tocant 的url编码是iso-8859-1(查看tocat/conf/server.xml 中的connector 节点没有写uriencoding="xxxxxx") 如下:

复制代码 代码如下:

      <connector port="8080" protocol="http/1.1"
              connectiontimeout="20000"
              redirectport="8443" />

如果我们在servlet 中写如下的代码

复制代码 代码如下:
   
    string username = request.getparameter("name");//name 是get 请求过来的参数,这里已经将get请求过来的字节码转化成iso-8859-1的的码了,解码错误
    byte[] b = username.getbytes("iso-8859-1");//所以要重新转化为字节码,再用正确的编码方式解码,正确编码方式就是 jsp那个页面的编码方式,
    username =new string(b,"gbk");
    system.out.print(username );

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网