昨天的帖子
http://topic.csdn.net/u/20081203/22/7cf1f57c-7bb6-41ba-b77e-809d00741919.html?1157912837
都试过,还是不行,可能问题提的不清楚,不过还是谢谢,分已分给大家了今天把症状搞清楚了,重新整理如下可以传中文参数:
1.如果字数为偶数个,没有问题
2.如果字数为奇数个,最后一个显示为“?”,前面能正常显示;字数为一个直接显示“?”流程:
JSP表单提交---存到MySQL数据库---读到JSP页面作为URI参数---Action中用request.getParameter()抓取显示我的JSP页面字符设置均为<%@ page pageEncoding="UTF-8"%>
数据库用的字符集为“UTF-8”用了一个spring自带字符过滤器,设置为“UTF-8”在web.xml文件中有如下配置<Connector port="8080" URIEncoding="UTF-8"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" useBodyEncodingForURI="false"/>
<Connector port="8009" URIEncoding="UTF-8"
enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" useBodyEncodingForURI="false" />
在Action中有如下输出代码:System.out.println(request.getParameter("allianceName"));
String str = request.getParameter("allianceName") ;
try {
str = new String(str.getBytes("ISO-8859-1"),"UTF-8") ;
System.out.println(str) ;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}若参数为“社区中心”
则该处输出分别为:
社区?
???我想应该描述的很清楚了,大家有何想法,呵呵
http://topic.csdn.net/u/20081203/22/7cf1f57c-7bb6-41ba-b77e-809d00741919.html?1157912837
都试过,还是不行,可能问题提的不清楚,不过还是谢谢,分已分给大家了今天把症状搞清楚了,重新整理如下可以传中文参数:
1.如果字数为偶数个,没有问题
2.如果字数为奇数个,最后一个显示为“?”,前面能正常显示;字数为一个直接显示“?”流程:
JSP表单提交---存到MySQL数据库---读到JSP页面作为URI参数---Action中用request.getParameter()抓取显示我的JSP页面字符设置均为<%@ page pageEncoding="UTF-8"%>
数据库用的字符集为“UTF-8”用了一个spring自带字符过滤器,设置为“UTF-8”在web.xml文件中有如下配置<Connector port="8080" URIEncoding="UTF-8"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" useBodyEncodingForURI="false"/>
<Connector port="8009" URIEncoding="UTF-8"
enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" useBodyEncodingForURI="false" />
在Action中有如下输出代码:System.out.println(request.getParameter("allianceName"));
String str = request.getParameter("allianceName") ;
try {
str = new String(str.getBytes("ISO-8859-1"),"UTF-8") ;
System.out.println(str) ;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}若参数为“社区中心”
则该处输出分别为:
社区?
???我想应该描述的很清楚了,大家有何想法,呵呵
char[] chars = new String(bytes, byteStart, bytesCount).toCharArray();
char[] charsPlus = new String(bytes, byteStart, bytesCount + 1).toCharArray(); if (chars.length == charsPlus.length)
return new String(bytes, byteStart, bytesCount - 1);
return new String(bytes, byteStart, bytesCount);
}此函数cut(request.getParameter("allianceName")toString(), 0,request.getParameter("allianceName")toString().length)
应该能格式化你的String里的中文!这样就不错了
url最长只能是2048个字节
不过我以前碰过这种乱码情况
如果你页面和数据库都是UTF-8字符
那应该不是字符集的问题
我以前就换了个mysql驱动就搞好了
System.out.println(request.getParameter("allianceName"));
String str = request.getParameter("allianceName") ;
try {
str = new String(str.getBytes(""),"UTF-8") ;
System.out.println(str) ;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
还需要将传递的参数改成 URL 编码。比如说传递:
http://localhost:8080/project/test.do?statement=大家好得换成:
http://localhost:8080/project/test.do?statement=%E5%A4%A7%E5%AE%B6%E5%A5%BD这种形式的 URL 编码在火狐下浏览器会自动帮你做这件事的,但是 IE 下就不会帮你做这件事了,为了兼容 IE,得把地址栏中的参数处理一下。
这个处理可以在服务端处理,也可以在客户端使用 encodeURI 这个 JavaScript 函数处理。