jsp中 ajax的get请求的中文乱码问题的解决方法_JSP教程-查字典教程网
jsp中 ajax的get请求的中文乱码问题的解决方法
jsp中 ajax的get请求的中文乱码问题的解决方法
发布时间:2016-12-29 来源:查字典编辑
摘要:一般Tocant的url编码是iso-8859-1(查看tocat/conf/server.xml中的Connector节点没有写URIEn...

一般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 );

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新JSP教程学习
    热门JSP教程学习
    编程开发子分类