没有转换,可以有两种办法解决,一个是在录入的JSP页面里添加下面的代码
<%@ page language="java" contentType="text/html; charset=GB2312"%>
或者是
在你得到数据后把数据转换一下
String strvalue = new String(strvalue.getBytes("ISO8859_1"),"GB2312");
strvalue 表示你得到的数据。
<%@ page language="java" contentType="text/html; charset=GB2312"%>
或者是
在你得到数据后把数据转换一下
String strvalue = new String(strvalue.getBytes("ISO8859_1"),"GB2312");
strvalue 表示你得到的数据。
String newstr = str;
try {
newstr = new String(str.getBytes("ISO-8859-1"));
}
catch (UnsupportedEncodingException uee) {
System.err.println("convert error!");
}
return newstr;
}插入数据前对string调用convertStr(string),取数据rs.getString不需要转换~直接就能在网页上显示中文
我的问题解决了,我总结一下,贴出来再结贴。^_^
我发现现在很多人老是问同一个问题,很多人在提出一个问题后,得到解决方法就OK了。
我们自己在一个问题上走了很多弯路,为什么不让我们的兄弟姐妹少走些弯路呢。
<%! public String convertStr(String str) {
String newstr = str;
try {
newstr = new String(str.getBytes("ISO-8859-1"));
}
catch (UnsupportedEncodingException uee) {
System.err.println("convert error!");
}
return newstr;
}
%>如果是不同浏览器之间的传递中文参数,可通过以下代码转换再可读出中文:
<% request.setCharacterEncoding("gb2312"); %><%! String trans(String chi)
{ byte[] temp;
String result = null;
try
{ temp=chi.getBytes("ISO-8859-1");
result=new String(temp,"GB2312");
}
catch(UnsupportedEncodingException e)
{
System.out.println (e.toString());
}
return result;
}
%>
例如:<%= trans(request.getParameter("Uname")) %>