大家好,我在网上找了很多关于这方面的资料,并都试过了,但是还是无法解决。
我提供一下我的一些代码,希望各位能帮我找出错误!一、数据库的连接 conn.jsp
<%
request.setCharacterEncoding("gb2312");
String host="localhost";
String user="root"; //mysql用户名
String pw="123456"; //mysql密码
String db="jspmo"; //留言本的数据库名
String tab="jspmo"; //留言本表名
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://localhost/jspmo?useUnicode=true&characterEncoding=gb2312";Connection con=DriverManager.getConnection (url,user,pw);Statement st=con.createStatement();
%>二、 首页加入了字符号转换的代码 index.jsp
<%!public String getStr(String s){
String str=s;
try{
byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e){return null;}
}
%>三、存储页面的读取转换代码 save.jsp
<%!
public String gb2iso(String qs){
try{
if (qs == null) return "NULL";
else return new String(qs.getBytes("ISO8859-1"), "gb2312");
}
catch(Exception e){
log("gb2iso error:"+e.getMessage());
}
return "NULL";
}
%>四、\MySQL\MySQL Server 4.1\my.ini 的设置
[client]port=3306[mysql]default-character-set=gb2312五、在JSP页面的首部都有
<%@ page contentType="text/html; charset=gb2312" pageEncoding="gb2312" language="java" import="java.sql.*" errorPage="" %>为什么现在无论是写入或者是读取都是乱码呢?请各位高手指教!谢谢
我提供一下我的一些代码,希望各位能帮我找出错误!一、数据库的连接 conn.jsp
<%
request.setCharacterEncoding("gb2312");
String host="localhost";
String user="root"; //mysql用户名
String pw="123456"; //mysql密码
String db="jspmo"; //留言本的数据库名
String tab="jspmo"; //留言本表名
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://localhost/jspmo?useUnicode=true&characterEncoding=gb2312";Connection con=DriverManager.getConnection (url,user,pw);Statement st=con.createStatement();
%>二、 首页加入了字符号转换的代码 index.jsp
<%!public String getStr(String s){
String str=s;
try{
byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e){return null;}
}
%>三、存储页面的读取转换代码 save.jsp
<%!
public String gb2iso(String qs){
try{
if (qs == null) return "NULL";
else return new String(qs.getBytes("ISO8859-1"), "gb2312");
}
catch(Exception e){
log("gb2iso error:"+e.getMessage());
}
return "NULL";
}
%>四、\MySQL\MySQL Server 4.1\my.ini 的设置
[client]port=3306[mysql]default-character-set=gb2312五、在JSP页面的首部都有
<%@ page contentType="text/html; charset=gb2312" pageEncoding="gb2312" language="java" import="java.sql.*" errorPage="" %>为什么现在无论是写入或者是读取都是乱码呢?请各位高手指教!谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货