?? login_confirm.java
字號:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import myBeans.SQLBean;
public class login_confirm extends HttpServlet{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String message=null;
String id=null;
id=req.getParameter("id").toString();
HttpSession session=req.getSession(true);
session.setAttribute("id",String.valueOf(id));
String password=null;
password=req.getParameter("password").toString();
String kind =null;
kind=req.getParameter("kind").toString();
String temp=getPassword(req,res,id,kind);
if( password.equals(temp))
goo(req,res,kind);
else {
message="用戶名或密碼有誤!";
doError(req,res,message);
}
}
public void goo(HttpServletRequest req, HttpServletResponse res,String kind)
throws ServletException,IOException
{
if(kind.equals("student")) {
RequestDispatcher rd = getServletContext().getRequestDispatcher("/student.jsp");
rd.forward(req, res);}
if(kind.equals("teacher")){
RequestDispatcher rd = getServletContext().getRequestDispatcher("/teacher.jsp");
rd.forward(req, res);}
if(kind.equals("studba")){
RequestDispatcher rd = getServletContext().getRequestDispatcher("/admin.jsp");
rd.forward(req, res);}
}
public String getPassword(HttpServletRequest req, HttpServletResponse res,
String id,String kind)
throws ServletException, IOException {
/* try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException e){
System.err.println("執行查詢有錯誤:"+e.getMessage() );
System.out.print("執行查詢有錯誤:"+e.getMessage()); //輸出到客戶端
}
Connection conn = null;
Statement st = null;
try{
conn = DriverManager.getConnection("jdbc:mysql://localhost/studb","root","125125");
st = conn.createStatement();
}catch(SQLException ex){
System.err.println("執行查詢有錯誤:"+ex.getMessage() );
System.out.print("執行查詢有錯誤:"+ex.getMessage()); //輸出到客戶端
}
String sql="select PASSWORD from "+kind+" where ID='"+id+"'";
String pw="";
try{
ResultSet rs = st.executeQuery(sql);
if(rs.next())
pw = rs.getString("PASSWORD");
}catch(Exception ec){
System.out.print(ec.toString());
}*/
SQLBean db= new SQLBean();
String pw="";
String sql="select PASSWORD from "+kind+" where ID='"+id+"'";
try{
ResultSet rs=db.executeQuery(sql);
if(rs.next()){
pw= rs.getString("PASSWORD");
}
}
catch(Exception e)
{ 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("/errorpage.jsp");
rd.forward(req, res);
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String action = req.getParameter("action");
if ("logout".equalsIgnoreCase(action)) {
HttpSession session=req.getSession(true);
session.invalidate();
RequestDispatcher rd = getServletContext().getRequestDispatcher("/login.jsp");
rd.forward(req, res);
} }
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -