关于jsp的中文读取问题?(高手请进!!!)
我用的是j2sdk142+tomcat5.05+MSSQL2000,从数据库读取中文资料在网页中显示正常,但当我在网页上写的中文资料要存回到数据库中是中文的字符变成乱码,因而存储失败。请问各位高手怎么解决,哪里有关于这个问题的资料?先谢了。 问题点数:100、回复次数:3Top
1 楼caina3(阿郎→偶什么都不会)回复于 2003-09-01 15:13:12 得分 50
一:
在JSP里加上<%@ page contentType="text/html;charset=gb2312" %>试试
二:
String aaa = request.getParameter("aaa");
if(aaa!=null){
aaa = new String(aaa.getBytes("iso-8859-1"),"gb2312")
out.println(aaa);
}
三:
strName = new String(request.getParameter("name").getBytes("ISO-8859-1"));
iso-8859-1这个地方可以多试几个参数
utf-8,GBK,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 "";
}
}
}
五:
request.setCharacterEncoding("gb2312");
随便找一个试试,
这些都是搜索到的。
Top
2 楼T_space(T_space)回复于 2003-09-01 15:15:02 得分 20
把代码转换,
byte[] temp_t=strs.getBytes("ISO8859-1");
String temp=new String(temp_t);
Top
3 楼seaman0916(沙漠孤鹰)回复于 2003-09-01 15:36:37 得分 30
caina3(阿郎)的方法挺多得呀!哈哈
随便试试吧!
写个JavaBean,以后用着也方便!
package beans ;
public class ISOtoGB2312
{
public String getConvert(String str)
{
try
{
byte[] byteStr=str.getBytes("ISO-8859-1");
return new String(byteStr,"gb2312");
}
catch(Exception e)
{
return str;
}
}
}
Top



