还是URL中文编码问题
Web服务器: Tomcat5.5
JDK:1.5.0_06
IE:选中“总是以UTF-8发送编码"
页面编码也为UTF-8
提交方式为PUT(GET、POST都试过,一样的结果)
我现在有个页面,有5个表单:email/password1/password2/昵称/验证码.
当用户在昵称中填写中文时,提交的URL如下:(如中文为“昵称”二字)
GET /projecteye/user/register.pe?email=xxx@gmail.com&password1=&password2=&nickname=%E6%98%B5%E7%A7%B0®isterCode= HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/x-silverlight, */*
Referer: http://localhost:8080/projecteye/user/register.jsp
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Host: localhost:8080
Connection: Keep-Alive
Cookie: JSESSIONID=61B6ED1EA7D0678182E0C2D59E48CB0C
问题在于:当我在服务器端解码的时候,无论用何种编码解码都不能得到正确的中文:
Filter里面的代码:
String tmp=request.getParameter("nickname");
String tmpc=request.getCharacterEncoding();
String tmpb=new String(tmp.getBytes());
String tmp2=new String(tmp.getBytes("iso8859-1"));
String tmp3=new String(tmp.getBytes("utf-8"));
String tmp4=new String(tmp.getBytes("gb2312"));
String tmp5=new String(tmp.getBytes("GBK"));
String tmp6=URLDecoder.decode(tmp);
String tmp7=URLEncoder.encode(tmp);
调试的输出结果:
tmp "æµç§°"
tmpc null
tmpb "????§°"
tmp2 "鏄电О"
tmp3 "忙聵碌莽搂掳"
tmp4 "????§°"
tmp5 "????§°"
tmp6 "æµç§°"
tmp7 "%3F%3F%3F%3F%A1%EC%A1%E3"
下面是register.jsp
<%@ page pageEncoding="utf-8"%>
<%
request.setCharacterEncoding("utf-8");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form method="put" action="register.pe">
邮件:<input type="text"name="email" value="xxx@gmail.com" /><br />
密码:<input type="password" name="password1" /><br />
再次输入密码:<input type="password" name="password2" /><br />
昵称<input type="text" name="nickname" /><br />
验证码:<image src="registercode" /><input type="text" name="registerCode"><br />
<input type="submit" value="注册"></form>
</body>
</html>
另外在网上搜索了下:
tomcat中server.xml配置文件也加上了参数
<connector .... useBodyEncodingForURI= "true" URIEncoding= "UTF-8" />
试了很多方法,都不行....请指教
一个很奇怪的问题:
我中文为"昵称",编码后要嘛是4个字符,要嘛是2个,怎么会是URL里面的3个呢?%E6%98%B5%E7%A7%B0