
还有就是MYSQL数据库设置为GBK字符的。
<%@
page
language="java"
import="java.util.*,java.sql.*"
pageEncoding="gb2312"%>
<%@
page
import="com.mysql.jdbc.Driver"
%>
<%
String
path
=
request.getContextPath()
String
basePath
=
request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"
%>
<!DOCTYPE
HTML
PUBLIC
"-//W3C//DTD
HTML
4.01
Transitional//EN">
<html>
<head>
<base
href="<%=basePath%>">
<title>My
JSP
'cc.jsp'
starting
page</title>
<meta
http-equiv="pragma"
content="no-cache">
<meta
http-equiv="cache-control"
content="no-cache">
<meta
http-equiv="expires"
content="0">
<meta
http-equiv="keywords"
content="keyword1,keyword2,keyword3">
<meta
http-equiv="description"
content="This
is
my
page">
<!--
<link
rel="stylesheet"
type="text/css"
href="styles.css">
-->
</head>
<body>
<%
request.setCharacterEncoding("GB2312")
String
no
=request.getParameter("txt1")
String
pswd=
request.getParameter("pswd1")
String
name=request.getParameter("name1")
String
sex=
request.getParameter("sex1")
//数据库用户名
String
userName="root"
//密码
String
userPasswd="123"
//数据库名
String
dbName="student"
//表名
String
tableName="tb_st"
//联结字符串
String
url="jdbc:mysql://localhost/"+dbName+"?useUnicode=true&characterEncoding=gb2312&user="+userName+"&password="+userPasswd
Class.forName("com.mysql.jdbc.Driver").newInstance()
Connection
conn=
DriverManager.getConnection(url)
Statement
stmt=conn.createStatement()
String
sql="select
*
from
tb_st
where
no='"+no+"'"
ResultSet
rs=stmt.executeQuery(sql)
if(rs.next())
{
out.println("注册失败,帐号已注册过")
//response.setHeader("Refresh","1URL=b.jsp")//实现网页跳转
response.sendRedirect("b.jsp")
}
else
{
Connection
connection=
DriverManager.getConnection(url)
Statement
statement=conn.createStatement()
String
sqll="INSERT
INTO
tb_st
(no,password,name,sex)
VALUES('"+no+"','"+pswd+"','"+name+"','"+sex+"')"
int
rest=statement.executeUpdate(sqll)%><br><center><font
color=blue
size=30
face=隶书><%
out.println("注册成功")%></font><br><%
String
sqlll="select
*
from
tb_st
where
no='"+no+"'"
ResultSet
rs1=stmt.executeQuery(sqlll)
if(rs1.next())
{%><font
color=red
size=20
face=隶书>请记住您的账号:</font><%
out.println(rs1.getString("no"))%><br><font
color=red
size=20
face=隶书>密码:</font><%
out.println(rs1.getString("password"))%><br><font
color=red
size=20
face=隶书>姓名:</font><%
out.println(rs1.getString("name"))%><br><font
color=red
size=20
face=隶书>性别:</font><%
out.println(rs1.getString("sex"))%></center><%
}
response.setHeader("Refresh","2URL=main.html")//实现网页跳转
}
%>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)