src部分
DBconnectc.java:
package DBconnect;
import java.sql.*;
public class DBconnects {
public static Connection DBconnecting(){
Connection c=null;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//System.out.println("加载驱动成功");
}catch(Exception e){
e.printStackTrace();
System.out.println("加载驱动失败");
}
try{
String str="jdbc:sqlserver://127.0.0.1:1433;databaseName=work";
String u="sa";
String p="123456";
c=DriverManager.getConnection(str,u,p);
//System.out.println("连接成功");
}catch(Exception e){
e.printStackTrace();
System.out.println("连接失败");
}
return c;
}
public static void DBclose(ResultSet rs,Statement stmt,Connection c){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("rs断开失败");
}
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("stmt断开失败");
}
}
if(c!=null){
try {
c.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("c断开失败");
}
}
}
}
Uers.java:
package userModel;
public class User {
private String userID;
private String userPassword;
private String userPassword_new;
private String username;
private String userphone;
private String userFID;
public String getUserPassword_new() {
return userPassword_new;
}
public void setUserPassword_new(String userPassword_new) {
this.userPassword_new = userPassword_new;
}
public String getUserphone() {
return userphone;
}
public void setUserphone(String userphone) {
this.userphone = userphone;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserFID() {
return userFID;
}
public void setUserFID(String userFID) {
this.userFID = userFID;
}
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
}
userCheck.java:
package userCheck;
import java.sql.*;
import DBconnect.DBconnects;
import userModel.User;
public class userChecks {
private static User user2;
public static int getRegister(User user){
Connection c=null;
ResultSet rs=null;
Statement stmt=null;
int i=0;
//插入数据
try{
c=DBconnects.DBconnecting();
stmt=c.createStatement();
String sqlstr="insert into student(uid,psd,name,phone,fid) values("
+"'" + user.getUserID() + "',"+"'"+ user.getUserPassword()+"',"
+"'" + user.getUsername() + "',"
+"'" + user.getUserphone() + "',"+"'"+ user.getUserFID()+"'"
+")";
//String sqlstr= " delete from guan252 where uid='1'";
System.out.println(sqlstr);
i = stmt.executeUpdate(sqlstr);
}catch(Exception e){
e.printStackTrace();
System.out.println("执行数据库语句失败");
}finally{
DBconnects.DBclose(rs,stmt,c);
}
return i;
}
public static int getUpdate(User user){
Connection c=null;
ResultSet rs=null;
Statement stmt=null;
int i=0;
try{
c=DBconnects.DBconnecting();
stmt=c.createStatement();
String sqlstr="update student set psd="+"'"+user.getUserPassword_new()+"'"
+"where uid="+"'"+user2.getUserID()+"'";
i = stmt.executeUpdate(sqlstr);
System.out.println(sqlstr);
}catch(Exception e){
e.printStackTrace();
System.out.println("执行数据库语句失败");
}finally{
DBconnects.DBclose(rs,stmt,c);
}
return i;
}
public static User getPassword(User user){
user2 = user;
Connection c=null;
ResultSet rs=null;
Statement stmt=null;
User curUser=new User();
try{
c=DBconnects.DBconnecting();
stmt=c.createStatement();
String sqlstr="select * from student where uid=+"+"'"+user.getUserID()+"'";
rs=stmt.executeQuery(sqlstr);
while(rs.next()){
curUser.setUserID(rs.getString(1));
curUser.setUserPassword(rs.getString(2));
}
System.out.println("DBconnects user"+user.getUserPassword());
System.out.println("DBconnects curUser"+user.getUserPassword());
}catch(Exception e){
e.printStackTrace();
System.out.println("执行数据库语句失败");
}finally{
DBconnects.DBclose(rs,stmt,c);
}
return curUser;
}
}
userActions.java:
package userAction;
import userCheck.userChecks;
import userModel.User;
public class userActions {
private User user;
private User curUser;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public User getCurUser() {
return curUser;
}
public void setCurUser(User curUser) {
this.curUser = curUser;
}
public String userRegister(){
int i=0;
String forward="refailure";
i = userChecks.getRegister(user);
if (i==1){
forward = "resuccess";
} else {
forward = "refailure";
}
return forward;
}
public String userUpdate(){
int i=0;
String forward="pdfailure";
i = userChecks.getUpdate(user);
if (i==1){
forward = "pdsuccess";
} else {
forward = "pdfailure";
}
return forward;
}
public String userLongin(){
curUser=new User();
String forward="failure";
curUser=userChecks.getPassword(user);
if(curUser.getUserID() != null){
if(user.getUserPassword().equals("123456") && curUser.getUserPassword().equals("123456")){
forward="firstpd";
}else if(user.getUserID().equals(curUser.getUserID())
&&
user.getUserPassword().equals(curUser.getUserPassword())){
forward="success";
}else{
forward="failure";
}
}
return forward;
}
}
choose.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>请选择功能</title>
</head>
<body>
<table border="0" align="center">
<tr>
<td align="center"><h1>图书检索系统</h1></td>
</tr>
<tr>
<td align="center"><h2>请选择功能</h2></td>
</tr>
<tr>
<td align="center"><a href="index.jsp"><img alt="" src="img/p1.png" onmouseover="mouseover()" name="p1" onmouseout="mouseout()"></a></td>
</tr>
<tr>
<td align="center"><a href="user/login.jsp"><img alt="" src="img/p3.png" onmouseover="mouseover2()" name="p2" onmouseout="mouseout2()"></a></td>
</tr>
</table>
<script type="text/javascript">
function mouseover(){
document.p1.src="img/p2.png";
}
function mouseout(){
document.p1.src="img/p1.png";
}
function mouseover2(){
document.p2.src="img/p4.png";
}
function mouseout2(){
document.p2.src="img/p3.png";
}
</script>
</body>
</html>
login.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>请登录</title>
</head>
<body>
<script type="text/javascript">
function aa(n,obj){
var cc=document.getElementById("ff"+n);
if (obj.value=="") {
cc.innerHTML=obj.title;
}else{
cc.innerHTML="";
}
}
</script>
<form action="openAction" method="post">
<table border="0" align="center">
<tr>
<td align="center" colspan="2"><h1>请登录</h1></td>
</tr>
<tr>
<td align="center">账号:</td>
<td align="center"><input type="text" name="user.userID" id="userName" value="" title="账号不能为空" onkeyup="aa(1,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff1"></label></font></td>
</tr>
<tr>
<td align="center">密码:</td>
<td align="center"><input type="password" name="user.userPassword" id="userPassword" value="" title="密码不能为空" onkeyup="aa(2,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff2"></label></font></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="登录" >
<a href="register.jsp">注册</a> </td>
</tr>
</table>
</form>
</body>
</html>
register.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>请注册</title>
</head>
<body>
<script type="text/javascript">
function aa(n,obj){
var cc=document.getElementById("ff"+n);
if (obj.value=="") {
cc.innerHTML=obj.title;
}else{
cc.innerHTML="";
}
}
</script>
<form action="registerAction" method="post">
<table border="0" align="center">
<tr>
<td align="center" colspan="2"><h1>请注册</h1></td>
</tr>
<tr>
<td align="center">账号:</td>
<td align="center"><input type="text" name="user.userID" id="userID" value="" title="账号不能为空" onkeyup="aa(1,this);" style="width: 150px"></td>
<td align="center" width="100px"><font color="red"><label id="ff1"></label></font></td>
</tr>
<tr>
<td align="center">密码:</td>
<td align="center"><input type="password" name="user.userPassword" id="userPassword" value="" title="密码不能为空" onkeyup="aa(2,this);" style="width: 150px"></td>
<td align="center" width="100px"><font color="red"><label id="ff2"></label></font></td>
</tr>
<tr>
<td align="center">名字:</td>
<td align="center"><input type="text" name="user.username" id="username" value="" title="姓名不能为空" onkeyup="aa(3,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff3"></label></font></td>
</tr>
<tr>
<td align="center">手机:</td>
<td align="center"><input type="text" name="user.userphone" id="userphone" value="" title="手机不能为空" onkeyup="aa(4,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff4"></label></font></td>
</tr>
<tr>
<td align="center">身份证号:</td>
<td align="center"><input type="text" name="user.userFID" id="userFID" value="" title="身份证号为空" onkeyup="aa(5,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff5"></label></font></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="确定" >
<input type="reset" value="重填" >
</td>
</tr>
</table>
</form>
</body>
</html>
firstpd.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>修改密码</title>
</head>
<body>
<script type="text/javascript">
function aa(n,obj){
var cc=document.getElementById("ff"+n);
if (obj.value=="") {
cc.innerHTML=obj.title;
}else{
cc.innerHTML="";
}
}
</script>
<%
out.print("<script type='text/javascript'>alert('首次登录必须改密码')</script>");
%>
<form action="updateAction" method="post">
<table border="0" align="center">
<tr>
<td align="center" colspan="2"><h1>修改密码</h1></td>
</tr>
<tr>
<td align="center">账号:</td>
<td align="center"><input type="text" name="user.userID" id="userName" value="" title="账号不能为空" onkeyup="aa(1,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff1"></label></font></td>
</tr>
<tr>
<td align="center">密码:</td>
<td align="center"><input type="password" name="user.userPassword" id="userPassword" value="" title="密码不能为空" onkeyup="aa(2,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff2"></label></font></td>
</tr>
<tr>
<td align="center">确定密码:</td>
<td align="center"><input type="password" name="user.userPassword_new" id="userPassword_new" value="" title="确定密码为空" onkeyup="aa(3,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff3"></label></font></td>
</tr>
<tr>
<td align="center">手机:</td>
<td align="center"><input type="text" name="user.userPhone" id="userPhone" value="" title="手机不能为空" onkeyup="aa(4,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff4"></label></font></td>
</tr>
<tr>
<td align="center">身份证号:</td>
<td align="center"><input type="text" name="user.userFID" id="userFID" value="" title="身份证号为空" onkeyup="aa(5,this);" style="width: 150px"></td>
<td align="center" width="150px"><font color="red"><label id="ff5"></label></font></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="确定" >
<input type="reset" value="重填" >
</td>
</tr>
</table>
</form>
</body>
</html>
版权声明:本文为zgw77477原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。