jsp 页面用下面3句语句来保证是gbk 编码
<%@ page session="true" %>
<%@ page contentType="text/html;charset=gbk" %>
<%@page pageEncoding="gbk"%>
<%request.setCharacterEncoding("gbk");%>
数据库连接用如下语句
String sConnStr ="jdbc:mysql://localhost:3306/test?user=michael&password=123456&useUnicode=true&characterEncoding=gbk" ;
并且在mysql的my.ini的内容如下
basedir=D:/mysql
#bind-address=127.0.0.1
datadir=D:/mysql-data/data
default_character_set=gbk
#language=D:/mysql/share/your language directory
#slow query log#=
#tmpdir#=
#port=3306
#set-variable=key_buffer=16M
[WinMySQLadmin]
Server=D:/mysql/bin/mysqld-nt.exe
user=michael
password=123
[client]
default_character_set=gbk
读jsp页面之间传递的参数在页面显示正常
在dos命令行下插入数据后,显示也正常
其中一条插入语句如下:
<jsp:useBean id="reg" scope="page" class="test.chatreg" />
String strSQL="insert into chatreg(username , password , email ,homepage )
values('" + regName + "', '" + regPassword +"' , '" + regEmail + "' , '" + regHomepage + "') ";
reg.executeQuery(strSQL);