码迷,mamicode.com
首页 > Web开发 > 详细

URL参数中汉字转换为16进制Unicode形式

时间:2016-09-06 10:23:34      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

导入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");%>这样就不会出现乱码了。

URL参数中汉字转换为16进制Unicode形式

标签:

原文地址:http://www.cnblogs.com/chenlong-50954265/p/5844559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!