String str = "你要转换的字符";str = String(str.getBytes("ISO8859-1"),"GBK");
ISO8859-1转化为GBKstr = String(str.getBytes("GBK"),"ISO8859-1");
反之函数返回的是string字符串,不是byte数组
注意 ISO8859-1 9后面的符号是减号,不是你的下划线
ISO8859-1转化为GBKstr = String(str.getBytes("GBK"),"ISO8859-1");
反之函数返回的是string字符串,不是byte数组
注意 ISO8859-1 9后面的符号是减号,不是你的下划线
打开tomcat的server.xml文件,找到区块,加入如下一行:
URIEncoding=”GBK”
完整的应如下:<Connector port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000" disableUploadTimeout="true"
URIEncoding="GBK"/>
这样你的所有get方法就可以传递中文参数了!
我试了几个版本的都不行,包括最新的5.5.7建议楼主写个filter
简单句代码request.setCharacterEncoding("GBK")就搞定了,
何必自己用getBytes
Connection con=ds.getConnnection();
PreparedStatement pstmt=con.preparedStatement("select * from tablename);
ResultSet rs=pstmt.executeQuery();
while(rs.next()){
String sTemp=rs.getString("filed1");
String sfiled1=new String(stemp.getBytes("ISO-8859-1","GB2312");
...
}
以上是从数据库是取出来时做的处理.
如果要写入的话:
servletRequest.setCharacterEncoding("GB2312");
String result = new String(gbStr.getBytes("iso-8859-1")); }catch(Exception ex){
} 是你写反了