URL参数中汉字转换为16进制Unicode形式
导入JAR包: import java.net.*; 把汉字转换为16进制Unicode形式: String xw="新闻中心"; String name=URLEncoder.encode(xw,"utf-8"); 把16进制Unicode形式字符串转换为汉字: URLDecoder.decode("%E6%96%B0%E9%97%BB%E4%B8%AD%E5%BF%83","utf-8");
注意:从A(UTF-8)页面中跳到B页面时:参数name带有16进制参数值时,在B页面中使用,request.getParameter()获取的参数是乱码。还不能使用URLDecoder.decode(name,"utf-8");获取"新闻中心"; 补充: 在A页面中: <% String xw="新闻中心"; String name=URLEncoder.encode(xw,"utf-8"); request.setParameter("name","name");%> 在B页面中: <% String xw=URLDecoder.decode(new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8"),"utf-8");%>这样就不会出现乱码了。