loginservlet.java~21~
来自「野生动物系统的JAVA源码, 野生动物系统的JAVA源码」· JAVA~21~ 代码 · 共 89 行
JAVA~21~
89 行
package scout.sys_manage.login;
/**
* <p>Title: control center</p>
* <p>Description:when login,the operator inputs account an password into the textbox and submit.
* the servlet get those informations,check by access the table of database.
* the class jude it </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Chongqing Kemeida corporation</p>
* @author zengBo
* @version 1.0
*/
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import scout.database.util.*;
public class LoginServlet extends HttpServlet {
/**
* @param conf
* @throws ServletException
*/
public void init(ServletConfig conf) throws ServletException {
super.init(conf);
}
/**
* @param request
* @param response
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
checkUser(request, response);
} catch (Exception e) {}
}
/**
* flag=1:the account exist,but the password is error.
* flag=2:the account does'not exist.
* flag=3:a mistake that we dont't expect has occured!
* @param request
* @param response
*/
public void checkUser(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, Exception {
String gotoPage = "";
try {
String account = request.getParameter("account");
String password = request.getParameter("password");
String sqlAcc = "select * from login_info where account='" +
account + "'";
String sqlPas = "select * from login_info where account='" +
account +
"' and password='" + password + "'";
ConnDataBase cdb = new ConnDataBase();
Connection conn = cdb.getConnection();
Statement stmt = conn.createStatement();
ResultSet resPas = stmt.executeQuery(sqlPas);
if (resPas.next()) {
request.getSession().setAttribute("account", account);
resPas.close();
gotoPage = "index.jsp";
} else {
ResultSet resAcc = stmt.executeQuery(sqlAcc);
if (resAcc.next()) {
gotoPage = "sys_manage/login/index.jsp?flag=1";
request.getSession().setAttribute("account", account);
resAcc.close();
} else {
gotoPage = "sys_manage/login/error.jsp?flag=2";
}
}
stmt.close();
conn.close();
} catch (Exception e) {
System.out.print(e.getMessage());
gotoPage = "sys_manage/login/error.jsp?flag=3";
}
System.out.println(gotoPage);
response.sendRedirect(gotoPage);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?