您的位置:首页 > 数据库

jsp实现注册与登录页面+sqlsever2008

2013-11-18 00:03 615 查看
//index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%

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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>登陆</title>

<style type="text/css">

<!--

.STYLE2 {

font-size: 24px;

font-family: "宋体";

font-weight: bold;

color: #FF0000;

}

.STYLE3 {

font-family: "新宋体";

font-size: 16px;

}

.STYLE4 {color: #FF0000}

.STYLE5 {

font-size: 12px;

line-height: 14px;

text-decoration: none;

}

-->

</style>

</head>

<body>

<form name="form1" id="form1" action="Logon.jsp" method="post">

<h1 align="center" class="STYLE2 STYLE3">用户登陆</h1>

<table width="253" border="0" align="center">

<tr>

<td width="71" height="33"><div align="left">用户名:</div></td>

<td width="172"><input name="uid" type="text" class="input1" size="18" maxlength="18" /></td>

</tr>

<tr>

<td width="71" height="33"><div align="left">密  码:</div></td>

<td><input name="password" type="password" class="input1" size="18" maxlength="18" /></td>

</tr>

</table>

<table width="200" border="0" align="center">

<tr>

<br/>

<td><input type="submit" name="Submit" value="登陆" /></td>

<td><input type="reset" name="Submit2" value="重置" /></td>

</tr>

</table>

</form>

<table align="center">

<tr>

<td><p ><a href="Register.jsp" class="STYLE4">注册新用户</a></p></td>

</tr>

</table>

</body>

</html>

//

Logon.jsp

<%@ page language="java" import="java.sql.*" errorPage="" pageEncoding="utf-8"%>

<%

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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>登陆确认</title>

<script language="javascript">

function BackWard()

{

history.back();

}

</script>

<style type="text/css">

<!--

.STYLE2 {

font-size: 24px;

font-family:"新宋体"

font-weight: bold;

color: #FF0000;

}

.STYLE3 {

font-family: "新宋体";

font-size: 16px;

}

.STYLE4 {color: #FF0000}

.STYLE5 {

font-size: 12px;

line-height: 14px;

text-decoration: none;

}

-->

</style>

</head>

<body>

<%

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

//"com.microsoft.sqlserver.jdbc.SQLServerDriver"要与驱动类名一样

String url="jdbc:sqlserver://localhost:1433;databaseName=STUDENT";

//STUDENT为数据库名

String user="sa";

String userpassword="123456";

Connection conn= DriverManager.getConnection(url,user,userpassword);

Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

boolean a;

String uid=request.getParameter("uid");

String password=request.getParameter("password");

String sql="select * from S where UID='"+uid+"' and Password='"+password+"'";

ResultSet rs=stmt.executeQuery(sql);

a=rs.next();

if(a==false)

{rs.close();

session.setAttribute("uid",uid);

%>

<p>用户名或密码错误,请重新填写!</p>

<p><input type="button" name="Button2" value="返回" onclick="return BackWard()" /></p>

<%}

else

{

rs.close();

%>

<form name="form2" id="form2" method="post" action="Logoff.jsp">

:)欢迎您<%=uid %><input type="submit" name="Submit" value="注销" />

</form>

<%} %>

</body>

</html>

//Register1.jsp

<%@ page language="java" import="java.sql.*" errorPage="" pageEncoding="utf-8"%>

<%

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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>注册信息确认</title>

<style type="text/css">

<!--

.STYLE2 {

font-size: 24px;

font-family: "宋体";

font-weight: bold;

color: #FF0000;

}

.STYLE3 {

font-family: "新宋体";

font-size: 16px;

}

.STYLE4 {color: #FF0000}

.STYLE5 {

font-size: 12px;

line-height: 14px;

text-decoration: none;

}

-->

</style>

<script language="javascript">

function backward()

{

history.back();

}

</script>

</head>

<body>

<%

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

//"com.microsoft.sqlserver.jdbc.SQLServerDriver"要与驱动类名一样

String url="jdbc:sqlserver://localhost:1433;databaseName=STUDENT";

//STUDENT为数据库名

String user="sa";

String userpassword="123456";

Connection conn= DriverManager.getConnection(url,user,userpassword);

Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

String uid=request.getParameter("uid");

String sql="select * from S where uid='"+uid+"'";

ResultSet rs=stmt.executeQuery(sql);

if(rs.next())

{

rs.close();

stmt.close();

conn.close();

%>

<p>用户名不能重名,请重新选择!</p>

<p><input name="Button2" type="button" class="button1" onclick="backward()" value="返回上一步" /></p>

<%}

else{

rs.close();

String username=request.getParameter("username");

String sex=request.getParameter("sex");

String password=request.getParameter("password");

%>

<form action="Register2.jsp" method="post">

<input type="hidden" name="uid" value="<%=uid%>" />

<input type="hidden" name="username" value="<%=username%>" />

<input type="hidden" name="sex" value="<%=sex%>" />

<input type="hidden" name="password" value="<%=password%>" />

<div align="center"><b><font size="3">请认真检查下面的注册申请单.</font></b>

<hr width="100%" />

<table width="414" border="0" cellspacing="2" cellpadding="1"><tbody>

<tr>

<td width="107" align="right"><div align="center">用 户 名:</div></td>

<td width="297" align="left"><%=uid%></td></tr>

<tr>

<td width="107" align="right"><div align="center">密    码:</div></td>

<td width="297" align="left"><%=password%></td></tr>

<tr>

<td align="right"><div align="center">性    别:</div></td>

<td align="left"><%=sex%></td></tr>

<tr>

<td align="right"><div align="center">真实姓名:</div></td>

<td align="left"><%=username%></td></tr>

</tbody></table>

<hr />

<table width="200" border="0">

<tr>

<td><input name="Submit" type="submit" class="button1" value="确认" /></td>

<td><input name="Submit2" type="button" class="button1" onclick="backward()" value="返回上一步"/></td>

</tr>

</table></div>

</form>

<%}%>

</body>

</html>

//Register2.jsp

<%@ page language="java" import="java.sql.*" errorPage="" pageEncoding="utf-8"%>

<%

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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>注册确认</title>

<style type="text/css">

<!--

.STYLE2 {

font-size: 24px;

font-family: "宋体";

font-weight: bold;

color: #FF0000;

}

.STYLE3 {

font-family: "新宋体";

font-size: 16px;

}

.STYLE4 {color: #FF0000}

.STYLE5 {

font-size: 12px;

line-height: 14px;

text-decoration: none;

}

-->

</style>

</head>

<body>

<%

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

//"com.microsoft.sqlserver.jdbc.SQLServerDriver"要与驱动类名一样

String url="jdbc:sqlserver://localhost:1433;databaseName=STUDENT";

//STUDENT为数据库名

String user="sa";

String userpassword="123456";

Connection conn= DriverManager.getConnection(url,user,userpassword);

Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

String uid=request.getParameter("uid");

String username=request.getParameter("username");

String sex=request.getParameter("sex");

String password=request.getParameter("password");

String sql="insert into S values('"+uid+"','"+username+"','"+sex+"','"+password+"')";

stmt.executeUpdate(sql);

%>

<p> <font color="#CC0033"><%=uid %></font>:祝贺您,注册成功!</p>

3秒后自动返回登陆窗口,如果你不想等待,可以点击这里<a href="index.jsp">返回首页</a>

<%response.setHeader("Refresh","3;URL=index.jsp");%>

<p align="center"> </p>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="30" align="center" valign="top">

</td>

</tr>

</table>

</body>

</html>

//Logoff.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%

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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>用户注销</title>

<style type="text/css">

<!--

.STYLE2 {

font-size: 24px;

font-family: "宋体";

font-weight: bold;

color: #FF0000;

}

.STYLE3 {

font-family: "新宋体";

font-size: 16px;

}

.STYLE4 {color: #FF0000}

.STYLE5 {

font-size: 12px;

line-height: 14px;

text-decoration: none;

}

-->

</style>

</head>

<body>

<p>成功注销!<br />

</p>

5秒后自动返回首页,如果你不想等待,可以点击这里<a href="index.jsp">返回首页</a>

<%response.setHeader("Refresh","5;URL=index.jsp");%>

</body>

</html>

//Register.jsp

<%@ page language="java" import="java.util.*" errorPage="" pageEncoding="utf-8"%>

<%

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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>用户注册</title>

<style type="text/css">

<!--

.STYLE2 {

font-size: 24px;

font-family: "宋体";

font-weight: bold;

color: #FF0000;

}

.STYLE3 {

font-family: "新宋体";

font-size: 16px;

}

.STYLE4 {color: #FF0000}

.STYLE5 {

font-size: 12px;

line-height: 14px;

text-decoration: none;

}

-->

</style>

<script language ="JavaScript">

<!--

function CheckSubmit()

{

if( document.registerform.uid.value == "" )

{ alert("请输入用户名!"); document.registerform.uid.focus(); return false; }

if( document.registerform.password.value == "" )

{ alert("请输入密码!"); document.registerform.password.focus(); return false; }

if( document.registerform.password2.value == "" )

{ alert("请验证密码!"); document.registerform.password2.focus(); return false; }

if( document.registerform.password2.value != document.registerform.password.value )

{ alert("密码验证出错!"); document.registerform.password.focus(); return false; }

if( document.registerform.username.value == "" )

{ alert("请输入真实姓名!"); document.registerform.username.focus(); return false; }

return true;

}

</script>

</head>

<body>

<div align="center">

<p>请如实填写下面的注册申请单(*为必填项)</p>

<hr width="800" size="0" />

<form name="registerform" id="form1" method="post" action="Register1.jsp">

<table width="343" border="0">

<tr>

<td><div align="center">用 户 ID:</div></td>

<td><input name="uid" type="text" class="input1" size="20"/>

<span class="style1" style="color: red">*</span></td>

</tr>

<tr>

<td><div align="center">密    码:</div></td>

<td><input name="password" type="password" class="input1" size="20"/>

<span class="style1" style="color: red">*</span></td>

</tr>

<tr>

<td><div align="center">验证密码:</div></td>

<td><input name="password2" type="password" class="input1" size="20"/>

<span class="style1" style="color: red">*</span></td>

</tr>

<tr>

<td><div align="center">真实姓名:</div></td>

<td><input name="username" type="text" class="input1" size="20"/>

<span class="style1" style="color: red">*</span></td>

</tr>

<tr>

<td><div align="center">性    别:</div></td>

<td><input name="sex" type="radio" value="M" checked="checked" />



<input name="sex" type="radio" value="W" />

女<span class="style1" style="color: red">*</span></td>

</tr>

</table>

<hr width="800" size="0" />

<table width="294" border="0">

<tr>

<td width="147"><input name="Submit" type="submit" class="button1" value="注册" onclick="return CheckSubmit();" /></td>

<td width="137"><input name="Submit2" type="reset" class="button1" value="清除" /></td>

</tr>

</table></form>

</div>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: