📄 modifydo.java
字号:
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import log.CreateLogs;
import com.JDBConnection;
public class modifydo extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String message=null;
String id=null;
id=req.getParameter("id");
String password=null;
password= req.getParameter("password");
String password1=null;
password1=req.getParameter("password1");
String temp =getPassword(req,res,id);
if( password.equals(temp))
{
System.out.println("学生登陆成功");
goo(req,res,password1.trim(),id);
}
else {
System.out.println("学生登陆失败");
message="用户名或密码有误!";
doError(req,res,message) ;
}
}
public void goo(HttpServletRequest req, HttpServletResponse res,String password,String id)
throws ServletException,IOException
{
JDBConnection db= new JDBConnection();
String update="update userInfo set pwd='"+password+"' where stdno= '"+id+"'";
String message="";
if(db.executeUpdate(update))
{
message="修改密码成功!";
doSuccess(req,res,message);
System.out.println(message);
}
else
{
message="用户名或密码修改出错,请重试!";
doError(req,res,message) ;
System.out.println(message);
}
}
public String getPassword(HttpServletRequest req, HttpServletResponse res,
String id)
throws ServletException, IOException {
JDBConnection db= new JDBConnection();
String pw="";
String sql="select pwd from userInfo where stdno='"+id+"'";
try{
ResultSet rs=db.executeQuery(sql);
if(rs.next() ){
pw= rs.getString("pwd").trim();
}
db.closeConnection();
}
catch(Exception e)
{
CreateLogs.createLog(e, "modifydo.java");
System.out.print(e.toString());
}
return pw;
}
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/modify.jsp");
rd.forward(req, res);
}
public void doSuccess(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/login.jsp");
rd.forward(req, res);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -