主题:快死了!!请各位帮一下忙吧!(mysql乱码问题)!!
<%@page contentType="text/html;charset=gbk" language="java" import="java.sql.*,java.util.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gbk">
<title>合法检测</title>
</head>
<body>
<%!String User_Name,User_Password1,User_Password2,User_Email,User_Sex,User_Address,User_Year,User_Month,User_Day,User_Birthday,User_QQ,sql;%>
<%!Connection conn;%>
<%! ResultSet rs;%>
<%
User_Name=request.getParameter("username");
User_Name=new String(User_Name.getBytes("ISO-8859-1"),"gbk");
User_Password1=request.getParameter("password1");
User_Password2=request.getParameter("password2");
User_Sex=request.getParameter("sex");
User_Sex=new String(User_Sex.getBytes("ISO-8859-1"),"gbk");
User_Email=request.getParameter("email");
User_Address=request.getParameter("address");
User_Address=new String(User_Address.getBytes("ISO-8859-1"),"gbk");
User_Year=request.getParameter("year");
User_Month=request.getParameter("month");
User_Day=request.getParameter("day");
User_QQ=request.getParameter("qq");
request.setCharacterEncoding("gbk");
if((User_Name.indexOf("'")>0)||(User_Name.indexOf(" ")>0)||(User_Name.indexOf("@")>0)||(User_Name.indexOf("=")>0)||(User_Name.indexOf("%")>0))
{//检查是否含有非法字符
response.sendRedirect("err.jsp?flag=1");
return;
}
if((User_Password1.length()<6)||(User_Password1.length()>12))
{//检验密码长度
response.sendRedirect("err.jsp?flag=2");
return;
}
if(!User_Password1.equals(User_Password2))
{//检验密码是否相等
response.sendRedirect("err.jsp?flag=3");
return;
}
if(User_Email.equals(""))
{//检验邮箱是否为空
response.sendRedirect("err.jsp?flag=4");
return;
}
if(!User_Year.equals(""))
{//获取生日
if((User_Month.equals(""))&&(User_Day.equals("")))
User_Birthday="秘密";
else
User_Birthday=User_Year+"年"+User_Month+"月"+User_Day+"日";
}
else
{
if((User_Month.equals(""))&&(User_Day.equals("")))
User_Birthday="秘密";
else
User_Birthday=User_Month+"月"+User_Day+"日";
}
try{
Class.forName("org.git.mm.mysql.Driver").newInstance();
}catch(ClassNotFoundException e){}
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=laoji");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql="select * from user where user_name='"+User_Name+"'";
//检查用户名是否已经存在
rs=stmt.executeQuery(sql);
rs.last();
if(rs.getRow()>0)
{
out.print("用户名已经存在");
}
else
{//在user表中插入用户注册信息
sql="insert into user(user_name,user_password,user_sex,user_Email,user_QQ,user_address,user_birthday)";
sql=sql+"values('"+User_Name+"','"+User_Password1+"','"+User_Sex+"','"+User_Email+"','"+User_QQ+"','"+User_Address+"','"+User_Birthday+"')";
stmt.executeUpdate(sql);//执行添加操作
session.putValue("username",User_Name);
out.println("<font size=3 color=red>正在处理信息,请稍后......</font><meta http-equiv='refresh' content='2;url=zcok.jsp'>");
}
stmt.close();
%>
</body>
</html>
总是显示??那为高手指点一下!小第感激不尽!!!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gbk">
<title>合法检测</title>
</head>
<body>
<%!String User_Name,User_Password1,User_Password2,User_Email,User_Sex,User_Address,User_Year,User_Month,User_Day,User_Birthday,User_QQ,sql;%>
<%!Connection conn;%>
<%! ResultSet rs;%>
<%
User_Name=request.getParameter("username");
User_Name=new String(User_Name.getBytes("ISO-8859-1"),"gbk");
User_Password1=request.getParameter("password1");
User_Password2=request.getParameter("password2");
User_Sex=request.getParameter("sex");
User_Sex=new String(User_Sex.getBytes("ISO-8859-1"),"gbk");
User_Email=request.getParameter("email");
User_Address=request.getParameter("address");
User_Address=new String(User_Address.getBytes("ISO-8859-1"),"gbk");
User_Year=request.getParameter("year");
User_Month=request.getParameter("month");
User_Day=request.getParameter("day");
User_QQ=request.getParameter("qq");
request.setCharacterEncoding("gbk");
if((User_Name.indexOf("'")>0)||(User_Name.indexOf(" ")>0)||(User_Name.indexOf("@")>0)||(User_Name.indexOf("=")>0)||(User_Name.indexOf("%")>0))
{//检查是否含有非法字符
response.sendRedirect("err.jsp?flag=1");
return;
}
if((User_Password1.length()<6)||(User_Password1.length()>12))
{//检验密码长度
response.sendRedirect("err.jsp?flag=2");
return;
}
if(!User_Password1.equals(User_Password2))
{//检验密码是否相等
response.sendRedirect("err.jsp?flag=3");
return;
}
if(User_Email.equals(""))
{//检验邮箱是否为空
response.sendRedirect("err.jsp?flag=4");
return;
}
if(!User_Year.equals(""))
{//获取生日
if((User_Month.equals(""))&&(User_Day.equals("")))
User_Birthday="秘密";
else
User_Birthday=User_Year+"年"+User_Month+"月"+User_Day+"日";
}
else
{
if((User_Month.equals(""))&&(User_Day.equals("")))
User_Birthday="秘密";
else
User_Birthday=User_Month+"月"+User_Day+"日";
}
try{
Class.forName("org.git.mm.mysql.Driver").newInstance();
}catch(ClassNotFoundException e){}
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=laoji");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql="select * from user where user_name='"+User_Name+"'";
//检查用户名是否已经存在
rs=stmt.executeQuery(sql);
rs.last();
if(rs.getRow()>0)
{
out.print("用户名已经存在");
}
else
{//在user表中插入用户注册信息
sql="insert into user(user_name,user_password,user_sex,user_Email,user_QQ,user_address,user_birthday)";
sql=sql+"values('"+User_Name+"','"+User_Password1+"','"+User_Sex+"','"+User_Email+"','"+User_QQ+"','"+User_Address+"','"+User_Birthday+"')";
stmt.executeUpdate(sql);//执行添加操作
session.putValue("username",User_Name);
out.println("<font size=3 color=red>正在处理信息,请稍后......</font><meta http-equiv='refresh' content='2;url=zcok.jsp'>");
}
stmt.close();
%>
</body>
</html>
总是显示??那为高手指点一下!小第感激不尽!!!