?? teacherloginsvlt.java
字號:
import java.io.*;
import myBeans.SQLBean;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TeacherLoginSvlt extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String pw1=null;
String pw2=null;
String action = req.getParameter("action");
ResultSet rs=null;
if ("update".equalsIgnoreCase(action)) {
String tea_id =req.getParameter("id");
pw1=req.getParameter("pw1");
pw2=req.getParameter("pw2");
if(pw1.equals("") || pw2.equals("") || pw1==null || pw2==null)
doError(req,res,"密碼不能為空!");
else if(doUpdate(req,res,pw1,pw2,tea_id)!=0)
res.sendRedirect("/0903/teacher.jsp");
}
}
public int doUpdate(HttpServletRequest req, HttpServletResponse res,
String pw1,String pw2,String id)
throws ServletException, IOException{
int num=0;
if(!pw1.equals(pw2))
doError(req,res,"密碼不一致,請重輸!");
else{
SQLBean db = new SQLBean();
String sql = "update teacher set PASSWORD='"+pw1+"' where ID='"+id+"'";
num = db.executeInsert(sql);
if(num==0) doError(req,res,"更新失敗");
}
return num;
}
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
public void sendResultSet(HttpServletRequest req, HttpServletResponse res,
java.sql.ResultSet rs, String target)
throws ServletException, IOException {
req.setAttribute("rs", rs);
RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
rd.forward(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -