byte[]b = str . getbytes(" ISO-8859-1 ");
壹般默認是ISO-8859-1編碼。
POst方式提交的表單數據壹般都有漢字。
獲得之前:請求。setcharacterencoding(" gbk ");
發送中文數據前:response . setcontenttype(" text/html;charset = GBK ");
對於JSP頁面,在獲取請求參數之前:
& lt% request . setcharacterencoding(" GB 2312 ")% & gt;
& lt% @頁content type = " text/html;charset = GBK " % & gt;
此外
string name = request . getparameter(" name ");
妳得到的是亂碼
name =新字符串(name . getbytes(" ISO-8859-1 ")," GBK ")
這裏第壹行中name的Unicode值是用ISO-8859-1編碼轉換的。調用第二行將獲得原始的GBK編碼值,並用新的字符串重建字符串的Unicode編碼。