员工培训系统,
servlet层:
package sevelet; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import dao.dao; import bean.section; import bean.student; import bean.teacher; import bean.job; /** * Servlet implementation class sevelet */ @WebServlet("/sevelet") public class sevelet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public sevelet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request,response); response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String method=request.getParameter("method"); dao p=new dao(); if(method.equals("login")) { String user=request.getParameter("user"); String num=request.getParameter("num"); String password=request.getParameter("password"); if(user.equals("管理员")) { try { if(p.checkM(num, password)) { request.getRequestDispatcher("loginM.jsp").forward(request, response); } else { System.out.println("用户名或密码错误!请重新登录!"+num+password); request.getRequestDispatcher("user.jsp").forward(request, response); } } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } else if(user.equals("员工")) { try { if(p.checkS(num, password)) { student a=p.Mgetstudent(num); request.setAttribute("Astudent",a); request.getRequestDispatcher("loginS.jsp").forward(request, response); } else { System.out.println("用户名或密码错误!请重新登录!"+num+password); request.getRequestDispatcher("user.jsp").forward(request, response); } } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } else if(user.equals("教师")) { try { if(p.checkT(num, password)) { teacher a=p.Mgetteacher(num); request.setAttribute("Ateacher",a); request.getRequestDispatcher("loginT.jsp").forward(request, response); } else { System.out.println("3"); System.out.println("用户名或密码错误!请重新登录!"+num+password); request.getRequestDispatcher("user.jsp").forward(request, response); } } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } } else if(method.equals("setp")) { try { List<section> list1=p.Mfindsection(); List<job> list2=p.Mfindjob(); request.setAttribute("Asection",list1); request.setAttribute("Ajob",list2); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("setP.jsp").forward(request, response); } else if(method.equals("add")) { String user=request.getParameter("user"); String ID=request.getParameter("ID"); String password=request.getParameter("password"); String name=request.getParameter("name"); String sex=request.getParameter("sex"); String section=request.getParameter("section"); String job=request.getParameter("job"); try { if(p.add(user,name,ID,sex,job,section,password)) { request.getRequestDispatcher("manager1.jsp").forward(request, response); } else { System.out.println("添加失败!"); request.getRequestDispatcher("loginM.jsp").forward(request, response); } } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } else if(method.equals("find")) { String user=request.getParameter("user"); String string1=request.getParameter("string1"); String string2=request.getParameter("string2"); if(user.equals("员工")) { List<student> list=new ArrayList<student>(); try { list=p.Mfindstudent(string1, string2); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.setAttribute("user",user); request.setAttribute("Astudent",list); request.getRequestDispatcher("findP2.jsp").forward(request, response); } else { List<teacher> list=new ArrayList<teacher>(); try { list=p.Mfindteacher(string1, string2); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.setAttribute("user",user); request.setAttribute("Ateacher",list); request.getRequestDispatcher("findP2.jsp").forward(request, response); } } else if(method.equals("set")) { String user=request.getParameter("user"); String ID=request.getParameter("ID"); String name=request.getParameter("name"); try { if(p.set(user,ID, name)) System.out.println("设置成功"); else System.out.println("设置失败"); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } if(user.equals("section")) request.getRequestDispatcher("setsection1.jsp").forward(request, response); else if(user.equals("job")) request.getRequestDispatcher("setjob1.jsp").forward(request, response); } else if(method.equals("sectionset")) { try { List<section> list=p.Msection(); request.setAttribute("Asection",list); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("sectionset.jsp").forward(request, response); } else if(method.equals("jobset")) { try { List<job> list=p.Mjob(); request.setAttribute("Ajob",list); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("jobset.jsp").forward(request, response); } else if(method.equals("delete")) { String user=request.getParameter("user"); String ID=request.getParameter("ID"); try { p.delete(ID,user); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } if(user.equals("section")) { List<section> list; try { list = p.Msection(); request.setAttribute("Asection",list); request.getRequestDispatcher("sectionset.jsp").forward(request, response); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } else if(user.equals("job")) { try { List<job> list=p.Mjob(); request.setAttribute("Ajob",list); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("jobset.jsp").forward(request, response); } } else if(method.equals("update")) { try { String user=request.getParameter("user"); String ID=(String) request.getSession().getAttribute("ID"); String name=request.getParameter("name"); p.update(user,name,ID); List<section> list=p.Msection(); request.setAttribute("Asection",list); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("sectionset.jsp").forward(request, response); } else if(method.equals("beforeupdate")) { String user=request.getParameter("user"); String ID=request.getParameter("ID"); try { List<section> list1 = p.Mfindsection(); List<job> list2=p.Mfindjob(); request.setAttribute("Asection",list1); request.setAttribute("Ajob",list2); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } if(user.equals("student")) { try { student a = p.Mgetstudent(ID); request.setAttribute("Astudent",a); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("updatestudent.jsp").forward(request, response); } else { try { teacher a = p.Mgetteacher(ID); request.setAttribute("Ateacher",a); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("updateteacher.jsp").forward(request, response); } } else if(method.equals("update2")) { String user=request.getParameter("user"); String ID=(String) request.getSession().getAttribute("ID"); String name=request.getParameter("name"); String sex=request.getParameter("sex"); String job=request.getParameter("job"); String section=request.getParameter("section"); try { List<section> list1 = p.Mfindsection(); List<job> list2=p.Mfindjob(); request.setAttribute("Asection",list1); request.setAttribute("Ajob",list2); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } if(user.equals("student")) { try { p.update2(user,ID,name,sex,job,section); student a = p.Mgetstudent(ID); request.setAttribute("Astudent",a); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("updatestudent.jsp").forward(request, response); } else { try { p.update2(user,ID,name,sex,job,section); teacher a = p.Mgetteacher(ID); request.setAttribute("Ateacher",a); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("updateteacher.jsp").forward(request, response); } } else if(method.equals("setclass")) { try { List<teacher> list=p.Mfindteacher1(); request.setAttribute("Ateacher",list); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("setclass.jsp").forward(request, response); } else if(method.equals("setclass1")) { String ID=request.getParameter("ID"); String name=request.getParameter("name"); String teacher=request.getParameter("teacher"); try { if(p.addclass(ID, name, teacher)) { List<teacher> list=p.Mfindteacher1(); request.setAttribute("Ateacher",list); } } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.getRequestDispatcher("setclass.jsp").forward(request, response); } } }