是不是你在JSP中的中文处理写的有问题呀,
我不太清楚你的意思,那在JSP中看到是什么,
我给你一段中文处理,看你能不能帮上忙
public String getStr(String str)//中文处理
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
e.printStackTrace() ;
}
return "null";
}
我不太清楚你的意思,那在JSP中看到是什么,
我给你一段中文处理,看你能不能帮上忙
public String getStr(String str)//中文处理
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
e.printStackTrace() ;
}
return "null";
}
第一:
在jsp页面加入:
<%@ page contentType="text/html; charset=gb2312" %>
或者在servlet里面
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312");
上面的如果在不行就用如下的方法在数据入库前进行调用:
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
content = new String(content.getBytes("ISO8859_1"),"GB2312");
主要是要在连接URL加上这些属性
useUnicode=true&characterEncoding=GB2312";
String mysqlURL="jdbc:mysql_caucho://localhost:3306/pic_db&useUnicode=true&characterEncoding=GB2312";
我把&换成?也不行。出错。编译没错,执行出错。我的环境的是 jsp+resin+mysql
try
{
CharToByteConverter toByte = CharToByteConverter.getConverter("gb2312");
byte[] orig = toByte.convertAll(s.toCharArray());
char[] dest = new char[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (char)(orig[i] & 0xFF);
return new String(dest);
}
catch (Exception e) {
System.out.println(e);
return s;
}
}
先把你要插入数据的sql转为Ascii码就行了,这样在数据库你面看到的是中文
读出来的时候用一般的String(s.getBytes("ISO8859_1"),"gb2312"); 方法即可