1 2 3 4

12.8

员工培训系统最后一弹。

servlet层代码

package servlet;

import java.io.IOException;

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 javax.servlet.http.HttpSession;

import dao.*;
import entity.*;

/**
 * Servlet implementation class IndexServlet
 */
@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IndexServlet() {
        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
        //response.getWriter().append("Served at: ").append(request.getContextPath());
        
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String ID=request.getParameter("username");
        HttpSession session=request.getSession();
        session.setAttribute("ID", ID);//存储数据
        request.setAttribute("ID", ID);
        
        String password=request.getParameter("password");
        String method=request.getParameter("profession");
        StaffDaoImpl sd=new StaffDaoImpl();
        if("1".equals(method)) {
            try{
                System.out.println("管理员验证!!!");
                
                if("123456".equals(ID)&&"654321".equals(password)) {
                    System.out.println("管理员验证通过!!!");
                request.getRequestDispatcher("manage.jsp").forward(request, response);}
                else {
                    System.out.println("管理员验证未通过!!!");
                    request.getRequestDispatcher("index.jsp").forward(request, response);}
            }catch(Exception e){
                System.out.println("失败");
                e.printStackTrace();
            }
        }
        if("2".equals(method)) {
            try{
                System.out.println("教师验证!!!");
                
                String teacherpass=sd.teachershowpass(ID);
                
                    
                if(password.equals(teacherpass)) {
                    System.out.println("教师验证通过!!!");
                    response.getWriter().println("<script type='text/javascript'> alert('登录成功')</script>");
                    request.getRequestDispatcher("teacher.jsp").forward(request, response);}
                else {
                    System.out.println("教师验证未通过!!!");
                    response.getWriter().println("<script type='text/javascript'> alert('账号或密码错误')</script>");
                    request.getRequestDispatcher("index.jsp").forward(request, response);}
                
                

            }catch(Exception e){
                System.out.println("失败");
                e.printStackTrace();
            }
        }
        if("3".equals(method)) {
            try{
                System.out.println(1);
                String stupass=sd.stushowpass(ID);
                if(password.equals(stupass)) {
                    StaffDaoImpl sd1=new StaffDaoImpl();
                    java.util.List<Staff> list=sd1.stushow(ID);
                    
                    request.setAttribute("list", list);
                    response.getWriter().println("<script type='text/javascript'> alert('登录成功')</script>");
                    request.getRequestDispatcher("student.jsp").forward(request, response);}
                else {
                    response.getWriter().println("<script type='text/javascript'> alert('账号或密码错误')</script>");
                    request.getRequestDispatcher("index.jsp").forward(request, response);}
                

            }catch(Exception e){
                System.out.println("失败");
                e.printStackTrace();
            }
        }
        
        
        
        
        
        
        
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
package servlet;

import java.io.IOException;
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.StaffDaoImpl;
import entity.Staff;

/**
 * Servlet implementation class Manservlet
 */
@WebServlet("/Manservlet")
public class Manservlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Manservlet() {
        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
        //response.getWriter().append("Served at: ").append(request.getContextPath());
        
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String ID=request.getParameter("ID");
        String name=request.getParameter("name");
        String sex=request.getParameter("sex");
        String class1=request.getParameter("class1");
        String title=request.getParameter("title");
        String method=request.getParameter("method");
        String fangshi=request.getParameter("fangshi");
        StaffDaoImpl sd=new StaffDaoImpl();
        
        if("query".equals(method)) {
            try{
                
                if(fangshi.equals("1")) {java.util.List<Staff> list=sd.allteashow();
                
                request.setAttribute("list", list);
                request.getRequestDispatcher("allteashow.jsp").forward(request, response);}
                
                if(fangshi.equals("2")) {java.util.List<Staff> list=sd.allstushow();
                
                request.setAttribute("list", list);
                request.getRequestDispatcher("allstushow.jsp").forward(request, response);}
                
                System.out.println("listshow");
                

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("add".equals(method)) {
            try{
                
                if(fangshi.equals("1")) {sd.addtea(ID,name,sex,class1,title);
                request.getRequestDispatcher("manage.jsp").forward(request, response);}
                
                if(fangshi.equals("2")) {sd.addstu(ID,name,sex,class1,title);
                request.getRequestDispatcher("manage.jsp").forward(request, response);}
                
                System.out.println("listshow");
                

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("summary".equals(method)) {
            try{
                
                if(fangshi.equals("1")) {
                    java.util.List<Staff> list=sd.shownopass();
                    
                    request.setAttribute("list", list);
                }
                if(fangshi.equals("2")) {
                    java.util.List<Staff> list=sd.showexcellent();
                    
                    request.setAttribute("list", list);
                }
                
                System.out.println("listshow");
                request.getRequestDispatcher("managesummaryshow.jsp").forward(request, response);

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("deleteshow".equals(method)) {
            try{
                
                if(fangshi.equals("1")) {java.util.List<Staff> list=sd.allteashow();
                
                request.setAttribute("list", list);
                request.getRequestDispatcher("deleteteashow.jsp").forward(request, response);}
                
                if(fangshi.equals("2")) {java.util.List<Staff> list=sd.allstushow();
                
                request.setAttribute("list", list);
                request.getRequestDispatcher("deletestushow.jsp").forward(request, response);}
                
                System.out.println("listshow");
                

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("deletetea".equals(method)) {
            try{
                sd.deletetea(ID);
                request.getRequestDispatcher("manage.jsp").forward(request, response);
                System.out.println("listshow");
            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        if("deletestu".equals(method)) {
            try{
                sd.deletestu(ID);
                request.getRequestDispatcher("manage.jsp").forward(request, response);
                System.out.println("listshow");
            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("updateshow".equals(method)) {
            try{
                
                if(fangshi.equals("1")) {java.util.List<Staff> list=sd.allteashow();
                
                request.setAttribute("list", list);
                request.getRequestDispatcher("updateteashow.jsp").forward(request, response);}
                
                if(fangshi.equals("2")) {java.util.List<Staff> list=sd.allstushow();
                
                request.setAttribute("list", list);
                request.getRequestDispatcher("updatestushow.jsp").forward(request, response);}
                
                System.out.println("listshow");
                

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("updateshowshowtea".equals(method)) {
            try{java.util.List<Staff> list=sd.teashow(ID);
                
                request.setAttribute("list", list);
                request.getRequestDispatcher("updateteashow1.jsp").forward(request, response);
                
                System.out.println("listshow");
                

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("updateshowshowstu".equals(method)) {
            try{java.util.List<Staff> list=sd.stushow(ID);
                
                request.setAttribute("list", list);
                request.getRequestDispatcher("updatestushow1.jsp").forward(request, response);
                
                System.out.println("listshow");
                

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("updatetea".equals(method)) {
            String ID1=(String)request.getSession().getAttribute("ID");
            try{
                sd.updatetea(ID1,name,sex,class1,title);
                request.getRequestDispatcher("manage.jsp").forward(request, response);
                System.out.println("listshow");
            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("updatestu".equals(method)) {
            String ID1=(String)request.getSession().getAttribute("ID");
            try{
                sd.updatestu(ID1,name,sex,class1,title);
                request.getRequestDispatcher("manage.jsp").forward(request, response);
                System.out.println("listshow");
            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
package servlet;

import java.io.IOException;

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 javax.servlet.http.HttpSession;

import dao.StaffDaoImpl;
import entity.Staff;

/**
 * Servlet implementation class Stuservlet
 */
@WebServlet("/Stuservlet")
public class Stuservlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Stuservlet() {
        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
        //response.getWriter().append("Served at: ").append(request.getContextPath());
        
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String stuID=(String)request.getSession().getAttribute("stuID");
        
        String stuname=request.getParameter("stuname");
        String stusex=request.getParameter("stusex");
        String stuclass=request.getParameter("stuclass");
        String stutitle=request.getParameter("stutitle");
        
        String method=request.getParameter("method");
        
        StaffDaoImpl sd=new StaffDaoImpl();
        
        if("show".equals(method)) {
            try{
                
                java.util.List<Staff> list=sd.stushow(stuID);
                
                request.setAttribute("list", list);
                System.out.println("listshow");
                request.getRequestDispatcher("stushow.jsp").forward(request, response);

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        
        
        if("showupdate".equals(method)) {
            try{
                
                java.util.List<Staff> list=sd.stushow(stuID);
                
                request.setAttribute("list", list);
                System.out.println("listshow");
                request.getRequestDispatcher("stuupdate.jsp").forward(request, response);

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("update".equals(method)) {
            try{
                
                    System.out.println(1);
                    
                    sd.stuupdate(stuID,stuname,stusex,stuclass,stutitle);
                    request.getRequestDispatcher("student.jsp").forward(request, response);

                }catch(Exception e){
                    System.out.println("修改失败");
                    e.printStackTrace();
                }
        }
        
        if("showgrade".equals(method)) {
            try{
                
                java.util.List<Staff> list=sd.stushowgrade(stuID);
            
            request.setAttribute("list", list);
            System.out.println("listshow");
            request.getRequestDispatcher("stushowgrade.jsp").forward(request, response);

        }catch(Exception e){
            System.out.println("未能正确显示出个人信息");
            e.printStackTrace();
        }}
        
        
        
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
package servlet;

import java.io.IOException;
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.StaffDaoImpl;
import entity.Staff;

/**
 * Servlet implementation class Teaservlet
 */
@WebServlet("/Teaservlet")
public class Teaservlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Teaservlet() {
        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
        //response.getWriter().append("Served at: ").append(request.getContextPath());
        
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String teaID=(String)request.getSession().getAttribute("teaID");
        String teaname=request.getParameter("teaname");
        String teasex=request.getParameter("teasex");
        String teaclass=request.getParameter("teaclass");
        String teatitle=request.getParameter("teatitle");
        
        String stuname=request.getParameter("stuname");
        String stuID=request.getParameter("stuID");
        String course=request.getParameter("course");
        String grade=request.getParameter("grade");
        
        String method=request.getParameter("method");
        
        StaffDaoImpl sd=new StaffDaoImpl();
        
        if("show".equals(method)) {
            try{
                
                java.util.List<Staff> list=sd.teashow(teaID);
                
                request.setAttribute("list", list);
                System.out.println("listshow");
                request.getRequestDispatcher("teashow.jsp").forward(request, response);

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        
        
        if("showupdate".equals(method)) {
            try{
                
                java.util.List<Staff> list=sd.teashow(teaID);
                
                request.setAttribute("list", list);
                System.out.println("listshow");
                request.getRequestDispatcher("teaupdate.jsp").forward(request, response);

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("update".equals(method)) {
            try{
                
                    System.out.println(1);
                    
                    sd.teaupdate(teaID,teaname,teasex,teaclass,teatitle);
                    request.getRequestDispatcher("teacher.jsp").forward(request, response);

                }catch(Exception e){
                    System.out.println("修改失败");
                    e.printStackTrace();
                }
        }
        
        if("gradeadd".equals(method)) {
            try{
                
                    System.out.println(1);
                    
                    sd.gradeadd(stuID,stuname,course,grade,teaID);
                    request.getRequestDispatcher("gradeadd.jsp").forward(request, response);

                }catch(Exception e){
                    System.out.println("修改失败");
                    e.printStackTrace();
                }
        }
        
        if("showgrade".equals(method)) {
            try{
                
                java.util.List<Staff> list=sd.gradeshow(teaID);
                
                request.setAttribute("list", list);
                System.out.println("listshow");
                request.getRequestDispatcher("gradeupdate.jsp").forward(request, response);

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("gradeshow".equals(method)) {
            try{
                
                java.util.List<Staff> list=sd.stushowgrade(stuID);
                
                request.setAttribute("list", list);
                System.out.println("listshow");
                request.getRequestDispatcher("gradeupdate1.jsp").forward(request, response);

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        if("updategrade".equals(method)) {
            try{
                
                    System.out.println(1);
                    String stuID1=(String)request.getSession().getAttribute("teaID");
                    sd.updategrade(stuID1,grade);
                    request.getRequestDispatcher("teacher.jsp").forward(request, response);

                }catch(Exception e){
                    System.out.println("修改失败");
                    e.printStackTrace();
                }
        }
        
        if("fangshi".equals(method)) {
            try{
                String fangshi=request.getParameter("fangshi");
                if(fangshi.equals("1")) {
                    java.util.List<Staff> list=sd.showpass();
                    
                    request.setAttribute("list", list);
                }
                if(fangshi.equals("2")) {
                    java.util.List<Staff> list=sd.showexcellent();
                    
                    request.setAttribute("list", list);
                }
                
                System.out.println("listshow");
                request.getRequestDispatcher("Summaryshow.jsp").forward(request, response);

            }catch(Exception e){
                System.out.println("未能正确显示出个人信息");
                e.printStackTrace();
            }
        }
        
        
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

 

posted @ 2020-12-08 22:41  小陈的太阳  阅读(187)  评论(0编辑  收藏  举报