1 2 3 4

11.12

持续更新人口普查系统

今天发表数据层和servlet层代码

数据层,由于使用之前一个模板的代码,所以一些命名并不准确,望各位大佬勿喷

package entity;

public class School {
    private String classname;
    private String classteacher;
    private String classplace;
    private String classnum;
    private String zhuname;
    private String ID;
    private String sex;
    private String minzu;
    private String education;
    public String getclassname() {
        return classname;
    }
    public void setclassname(String classname) {
        this.classname=classname;
    }
    
    public String getclassteacher() {
        return classteacher;
    }
    public void setclassteacher(String classteacher) {
        this.classteacher=classteacher;
    }
    
    public String getclassplace() {
        return classplace;
    }
    public void setclassplace(String classplace) {
        this.classplace=classplace;
    }
    public String getclassnum() {
        return classnum;
    }
    public void setclassnum(String classnum) {
        this.classnum = classnum;
    }
    public String getzhuname() {
        return zhuname;
    }
    public void setzhuname(String zhuname) {
        this.zhuname = zhuname;
    }
    public String getID() {
        return ID;
    }
    public void setID(String iD) {
        ID = iD;
    }
    public String getsex() {
        return sex;
    }
    public void setsex(String sex) {
        this.sex = sex;
    }
    public String getminzu() {
        return minzu;
    }
    public void setminzu(String minzu) {
        this.minzu = minzu;
    }
    public String geteducation() {
        return education;
    }
    public void seteducation(String education) {
        this.education = education;
    }
}

servlet层,其中涉及多个servlet文件

package SchoolAddServlet;
import java.util.*;


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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/SchoolAddServlet")
public class SchoolAddServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
    
    
    @Override
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String classname=request.getParameter("classname");
        String classteacher=request.getParameter("classteacher");
        String classplace=request.getParameter("classplace");
        String classnum=request.getParameter("classnum");
        String zhuname=request.getParameter("zhuname");
        String ID=request.getParameter("ID");
        String sex=request.getParameter("sex");
        String minzu=request.getParameter("minzu");
        String education=request.getParameter("education");
        
        School Subject =new School();
        Subject.setclassname(classname);
        Subject.setclassteacher(classteacher);
        Subject.setclassplace(classplace);
        Subject.setclassnum(classnum);
        Subject.setzhuname(zhuname);
        Subject.setID(ID);
        Subject.setsex(sex);
        Subject.setminzu(minzu);
        Subject.seteducation(education);
        
        SchoolDaoImpl sd = new SchoolDaoImpl();
        try{
            //System.out.println(1);
            sd.add(Subject);
            response.sendRedirect(request.getContextPath() + "/school.jsp");

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


}
package SchoolDeleteServlet;
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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/SchoolDelete")
public class SchoolDelete extends HttpServlet{
    private static final long serialVersionUID = 1L;
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
 
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String zhuname = request.getParameter("zhuname");
        /*String classteacher=request.getParameter("classteacher");
        String classplace=request.getParameter("classplace");*/
        School school=new School();
        school.setzhuname(zhuname);
        /*school.setclassteacher(classteacher);
        school.setclassplace(classplace);
        */
        SchoolDaoImpl sd = new SchoolDaoImpl();
        try {
            sd.delete(zhuname);
            response.sendRedirect(request.getContextPath() + "/school.jsp");
        }catch(Exception e) {
            System.out.println("删除失败");
            e.printStackTrace();
        }

}
}
package SchoolDeleteServlet;
import java.io.IOException;
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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/Schoolshowdelete")
public class Schoolshowdelete extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String zhuname=request.getParameter("zhuname");
        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.showdelete(zhuname);
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshowdelete.jsp").forward(request, response);

    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
package SchoolUpdate;
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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/SchoolUpdate")
public class SchoolUpdate extends HttpServlet{
    private static final long serialVersionUID = 1L;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        
        String zhuname=request.getParameter("zhuname");
        String ID=request.getParameter("ID");
        String sex=request.getParameter("sex");
        String minzu=request.getParameter("minzu");
        String education=request.getParameter("education");
        System.out.println(123456789);
        
        SchoolDaoImpl sd = new SchoolDaoImpl();
        try{
            System.out.println(159);
            sd.update(zhuname,ID,sex,minzu,education);
            response.sendRedirect(request.getContextPath() + "/school.jsp");

        }catch(Exception e){
            System.out.println("更新失败");
            e.printStackTrace();
        }
        
    }
}
package SchoolSelect;
import java.io.IOException;
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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/education")
public class education extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String education=request.getParameter("education");
        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.showdelete3(education);
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshow.jsp").forward(request, response);

    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
package SchoolSelect;
import java.io.IOException;
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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/minzu")
public class minzu extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String minzu=request.getParameter("minzu");
        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.showdelete2(minzu);
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshow.jsp").forward(request, response);

    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
package SchoolSelect;
import java.io.IOException;


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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/SchoolSelect")
public class SchoolSelect extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.select();
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshow.jsp").forward(request, response);

    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

}
package SchoolSelect;
import java.io.IOException;



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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/Schoolshow")
public class Schoolshow extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.select();
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshow.jsp").forward(request, response);
        request.getRequestDispatcher("schoolshow1.jsp").forward(request, response);
    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
package SchoolSelect;
import java.io.IOException;



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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/Schoolshow1")
public class schoolshow1 extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String zhuname=request.getParameter("zhuname");
        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.showdelete(zhuname);
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshow1.jsp").forward(request, response);

    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
package SchoolSelect;
import java.io.IOException;



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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/Schoolshow2")
public class schoolshow2 extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String zhuname=request.getParameter("zhuname");
        
        
        
        

    
        SchoolDaoImpl sd = new SchoolDaoImpl();
   
    try{
        
        //System.out.println(1);
        List<School> list = sd.showdelete(zhuname);
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshow1.jsp").forward(request, response);

    }catch(Exception e){
        System.out.println("失败");
        e.printStackTrace();
    }
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
package SchoolSelect;
import java.io.IOException;



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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/Schoolshowupdate")
public class Schoolshowupdate extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String zhuname=request.getParameter("zhuname");
        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.showdelete(zhuname);
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshowupdate1.jsp").forward(request, response);

    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

}
package SchoolSelect;
import java.io.IOException;
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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/sex")
public class sex  extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String sex=request.getParameter("sex");
        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.showdelete1(sex);
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshow.jsp").forward(request, response);

    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
package SchoolSelect;
import java.io.IOException;
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.SchoolDao;
import dao.SchoolDaoImpl;
import entity.School;
@WebServlet("/zhuname")
public class zhuname extends HttpServlet{
    private static final long serialVersionUID = 1L;
      
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String zhuname=request.getParameter("zhuname");
        SchoolDaoImpl sd = new SchoolDaoImpl();
        List<School> list = sd.showdelete(zhuname);
        request.setAttribute("list", list);
        request.getRequestDispatcher("schoolshow.jsp").forward(request, response);

    
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}

 

posted @ 2020-11-12 23:30  小陈的太阳  阅读(91)  评论(0编辑  收藏  举报