欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jsp中 ajax的get請求的中文亂碼問題的解決方法

 更新時間:2013年10月19日 15:45:53   作者:  
這篇文章介紹了jsp中ajax的get請求的中文亂碼問題的解決方法,有需要的朋友可以參考一下

一般Tocant 的url編碼是iso-8859-1(查看tocat/conf/server.xml 中的Connector 節(jié)點沒有寫URIEncoding="xxxxxx") 如下:

復(fù)制代碼 代碼如下:

      <Connector port="8080" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" />

如果我們在servlet 中寫如下的代碼

復(fù)制代碼 代碼如下:
   
    String username = request.getParameter("name");//name 是get 請求過來的參數(shù),這里已經(jīng)將get請求過來的字節(jié)碼轉(zhuǎn)化成iso-8859-1的的碼了,解碼錯誤
    byte[] b = username.getBytes("iso-8859-1");//所以要重新轉(zhuǎn)化為字節(jié)碼,再用正確的編碼方式解碼,正確編碼方式就是 jsp那個頁面的編碼方式,
    username =new String(b,"GBK");
    System.out.print(username );

相關(guān)文章

最新評論