做个转换:
String getCnString(String s){
String tmp;
byte[] b;
try{ b=s.getBytes("ISO8859-1");
tmp = new String(b);
return tmp;
}
catch(Exception ex){
}
return null;
}
String getCnString(String s){
String tmp;
byte[] b;
try{ b=s.getBytes("ISO8859-1");
tmp = new String(b);
return tmp;
}
catch(Exception ex){
}
return null;
}
解决方案 »
- 导出excel表问题,浏览器静悄悄的下载了,没有弹出窗口选择下载途径
- jsp中上传和下载怎么实现,有几种?
- 抓取的网页是乱码怎么解决
- url重写
- 安装了J2SDK1.4.1_01,但是java -version 还是显示JDK1.3.1_01.我装了ORACLE9I,但是所有ORACLE服务都以停止。
- 一个比较棘手的ajax的问题,希望大家能帮忙看看
- ACTIVEX的乱码问题
- jsp打印图片的问题!!倾家荡产180送~!!各位高手帮帮忙呀~~~~
- 我想用jdbc访问远程的SQL Server数据库,可怎么也连不上?
- 项目编码疑惑!!
- servlet 开发环境
- 如何设置TOMCAT4.0的虚拟目录?
也就是在存入之前转换就可以了,我用的是weblogic不知道对你是否一样
public static final String toChineseNoReplace(String strVal)
{
try
{
if (strVal == null)
{
return "";
}
else
{
strVal = strVal.trim();
strVal = new String(strVal.getBytes("ISO8859_1"), "GBK");
return strVal;
}
}
catch (Exception exp)
{
return "";
}
}将数据从数据库中取出后转换,将字符串由“GBK”转换为“ISO8859_1public static final String toISO(String strVal)
{
try
{
if (strVal == null)
{
return "";
}
else
{
strVal = new String(strVal.getBytes("GBK"), "ISO8859_1");
return strVal;
}
}
catch (Exception exp)
{
return "";
}
}
存入的时候保证汉字没有乱码,这样从数据库中读出来的就没有问题了,
也就是在存入之前转换就可以了,这是正确的!
以前我有类似问题,是因为要存储的中文数据从request中得到后就是乱吗,需要转换,如果不转化存储进去的就是乱吗,从数据库中读出当然也不对,这个也是正确的
下边我有一个,字符转化的代码,你可以看看!你的页面的字符集也要使gb2312的!
public static String charConvert(String strSource){
if (strSource == null){
return "";
}
else{
try{
//return new String(strSource.getBytes("GB2312"), "ISO-8859-1");
String str = new String(strSource.getBytes("ISO-8859-1"), "GB2312");
System.out.println(str);
return str;
}
catch (Exception ex){
System.out.println(ex.toString());
return "";
}
}
}
if(!str.equals(null))
str=str.getBytes("ISO8859-1","GBK");
<%@ page contentType="text/html; charset=UTF-8" %>
2. 设定JBuilder的编绎时的内码为ISO-8859-1.
JBuilder的菜单操作为Project --> general --> Enconding --> ISO-8859-1.设置成功, JBuilder下面的状态栏显示为ISO-8859-1. 并编绎成功。3. 如果数据是从Oracle数据库中取出, 则真接在页面显示,不须要转换。 如果是从页面接收回来的字符串, 则必须进行转换。 (setXXX方法中) public void setXXX(String newValue) {
this.newValue = ISOtoUTF-8(newValue);
}
public String ISOtoUTF8 (String aISOString) {
if (aISOString == null) return "";
try {
return new String (aISOString.getBytes("ISO-8859-1"),"UTF-8");
} catch (java.io.UnsupportedEncodingException e ) {
System.out.println(e.getMessage());
return "";
}
}
4. 如果要JDBC支持多国语言, 还要把nls_charset1.2.zip加入到classPath中或加入复制到web-info/classes下。这文件可以在%Oracle_Home%/JDBC/lib下找到。