是中文成了乱码了吗?
你的jsp里是不是用的charset = gb2312?
如果是的话,存之前先转换一下:
byte[] temp = string.getBytes("ISO8859-1");
String s = new String(temp);
再存s
试一下:)
你的jsp里是不是用的charset = gb2312?
如果是的话,存之前先转换一下:
byte[] temp = string.getBytes("ISO8859-1");
String s = new String(temp);
再存s
试一下:)
String s = new String(aaa.getBytes("8859-1"))
string namestr=request.getParameter("name");
String name=ndw String(namestr.getBytes("8859_1"),"gb2312");
out.println(name); <-------name 已经转化为中文
从另一个页面传来的中文字符,不做转码写入mysql,mysql中的数据就已经是中文的拉
若坐了转码,反而会得到????
String lEnc = request.getCharacterEncoding();
out.println("Encoding = "+lEnc);如果返回null的话,则需要在一开始设置编码,如下:
<%
request.setCharacterEncoding("GBK");//或者用GB2312编码;
%>如果不为null的话,则要做一下转换:
存入数据库的字符 = new String(原来字符.getBytes(lEnc), "GBK");
//或者用GB2312代替GBK再试试看。
<%@ page contentType="text/html; charset=gb2312" %>
2:在servlet里面:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312");//这是重要的
3:上面的如果在不行就用如下的方法在数据入库前进行调用:
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;
}
}
<%@ page import="aaa.bbb.ccc.*" contentType="text/html;charset=gb2312"%>String name=new String(request.getParameter("name").getBytes("8859_1"));
有用过jsp+mysql用Connector/J 3.0连接可以存入中文的嘛?
怎么会这样那
用mm.mysql.jdbc-1.2c可以存中文啊哎呀
愁死了