网络编程 
首页 > 网络编程 > 浏览文章

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

(编辑:jimmy 日期: 2024/9/23 浏览:3 次 )

一般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地址栏传中文显示乱码解决方法分享
下一篇:IE浏览器在post提交时中文乱码的解决方法
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap