房产信息管理系统--个人密码修改
个人密码修改:顾客或者房产经纪人登录后,可以输入旧密码、新密码、新密码确认修改个人密码,需要判断旧密码是否正确,新密码和新密码确认是否一致;(2分)我自己还加了一个功能哈哈,就是成功修改密码后会跳转到登录界面,重新登录
此功能涉及的是改
代码
User_ChangePassword.jsp
<%--
Created by IntelliJ IDEA.
User: mendianyu
Date: 2022/11/4
Time: 17:49
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改密码</title>
</head>
<body>
<form action="User_ChangePassword_back.jsp" method="get">
<p style="text-align:center;font-size:20px" >
密码修改
<br>
旧密码
<input type="text" name="Password0">
<br>
新密码
<input type="password" name="Password1">
<br>
请再次输入新密码
<input type="password" name="Password2">
<br>
<input type="submit" value="修改">
</p>
</form>
</body>
</html>
User_ChangePassword_back.jsp
<%@ page import="com.Dao.dao" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<%
String UserID= (String) session.getAttribute("UserID");
String Password2=(String)request.getParameter("Password2");
String Upassword= (String) session.getAttribute("Upassword");
String Password0=(String)request.getParameter("Password0");
String Password1=(String)request.getParameter("Password1");
if(!Password0.equals(Upassword))
{
out.print("<script language='javaScript'> alert('旧密码输入错误');window.history.back();</script>");
}
else if(Password0==""||Password1==""||Password2=="")
{
out.print("<script language='javaScript'> alert('输入为空');window.history.back();</script>");
}
else if(!Password2.equals(Password1))
{
out.print("<script language='javaScript'> alert('新密码两次输入不一致');window.history.back();</script>");
}
else
{
dao dao=new dao();
dao.ChangeUserPassword(Password2,UserID);
out.print("<script language='javaScript'> alert('修改成功,即将重新登录');</script>");
response.setHeader("refresh", "0;url=User_Login.jsp");
}
%>
</body>
</html>
Dao方法
public void ChangeUserPassword(String Upassword,String UserID)
{
Connection connection =util.getConnection();
PreparedStatement preparedStatement=null;
try {
String sql = "update 顾客基本信息表 set 密码=?where 顾客ID=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,Upassword);
preparedStatement.setString(2,UserID);
preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(preparedStatement);
util.close(connection);
}
}