对servlet的用途以及关联页面和dao层有了更清楚的认识,servlet层对于大项目的提高效率有很显著的效果
private void select(HttpServletRequest req, HttpServletResponse resp) throws IOException, Exception {
req.setCharacterEncoding("utf-8");
List<studentid> list = new ArrayList();
List<teacherid> list2 = new ArrayList();
int id = Integer.parseInt(req.getParameter("id"));
String password = req.getParameter("password");
studentid sid = new studentid();
HttpSession session = req.getSession();
list = dao.select();
list2 = dao2.select();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getId() == id) {
if (list.get(i).getPassword().equals(password)) {
session.setAttribute("id", id);
session.setAttribute("password", password);
Dao_Student daos = new Dao_Student();
student stu = daos.Select(id);
session.setAttribute("stu", stu);
req.getRequestDispatcher("student.jsp").forward(req, resp);
return;
}
}
}
for (int i = 0; i < list2.size(); i++) {
if (list2.get(i).getId() == id) {
if (list2.get(i).getPassword().equals(password)) {
session.setAttribute("id", id);
session.setAttribute("password", password);
Dao_Teacher daot = new Dao_Teacher();
teacher tea = daot.Select(id);
session.setAttribute("tea", tea);
req.getRequestDispatcher("teacher.jsp").forward(req, resp);
return;
}
}
}
if (id == 00000000 && password.equals("root")) {
req.getRequestDispatcher("manager.jsp").forward(req, resp);
return;
}
req.setAttribute("message", "账号不存在或密码错误,请重新输入");
req.getRequestDispatcher("menu.jsp").forward(req, resp);
return;
}