`
wandejun1012
  • 浏览: 2693777 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

url中文乱码

    博客分类:
  • java
 
阅读更多

 

背景:在JAVA类中输出一个URL,此URL中含有参数&UserName=刘德华

 

然后JSP中用request.getParameter('UserName')时,刘德华变成乱码。

 

剖析:在用GET方式传送时,默认用的是ISO8859-1。

而且tomcat在接受时也是默认用的ISO8859-1。

 

解决:在JAVA类中必须对刘德华进行转码,转成UTF8,如下:

 

"&nickName="+URLEncoder.encode(nickName, "UTF-8");

 

然后在JSP中接受时,先用ISO8859-1解码得到字节,再拼接成UTF-8。

 

代码如下:

<input type="text" name="nickName" value="<%= new String(request.getParameter("nickName").getBytes("ISO-8859-1"),"utf-8") %>"  placeholder="用户昵称" required="required" maxlength="20"  readonly="readonly">

 

 

refurl:http://blog.csdn.net/jinxinxin1314/article/details/4453390

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics