首页>代码>JSP+jdbc开发学生教务后台管理系统>/endDesign/src/servlet/admin.java
package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.User;
import dao.userDao;
import dao.kUser;

public class admin extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	public admin() {
		super();
	}


	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}


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


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		      request.setCharacterEncoding("utf-8");
		      String zsgc = request.getParameter("zsgc").replace(" ", "");
		      if(zsgc.equals("dl")){
		    	  
                     dlAdmin(request, response);
                     
		      }else if(zsgc.equals("zj")){
		    	  
		    	  addkUser(request, response);
		    	  allkUser(request, response);
		    	  
		      }else if(zsgc.equals("xg")){
		    	  
		    	  updatekUser(request, response);
		    	  allkUser(request, response);
		    	  
		      }else if(zsgc.equals("sc")){
		    	 
		    	  delectkUser(request, response);
		    	  allkUser(request, response);
		    	  
		      }else{
		    	  
		    	  request.getRequestDispatcher("error.jsp").forward(request, response);
		    	  
		      }
		      

	}


	public void init() throws ServletException {
		// Put your code here
	}
	
	private void dlAdmin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  	  String name = request.getParameter("word").replace(" ", "");
	      String pass = request.getParameter("pass");
	      User user = new User();
	      user.setU_word(name);
	      user.setU_pass(pass);
	      if(new userDao().adminUser(user)){
	    	  request.getSession().setAttribute("gly", name);
	    	  allkUser(request, response);
	      }else{
	    	  request.getRequestDispatcher("admin.jsp").forward(request, response);
	      }
	}
	private void addkUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		  String kcm = request.getParameter("kcm").replace(" ", "");
    	  String js  = request.getParameter("js");
    	  String jxl = request.getParameter("jxl");
    	  String sj  =request.getParameter("sj");
    	  String xf = request.getParameter("xf");
    	  kUser kuser = new kUser();
    	  kuser.setK_kcm(kcm);
    	  kuser.setK_js(js);
    	  kuser.setK_jxl(Integer.parseInt(jxl));
    	  kuser.setK_sj(sj);
    	  kuser.setK_xf(Integer.parseInt(xf));
          new userDao().addkUser(kuser);
	}
	
	private void updatekUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		  String id  =request.getParameter("id");
		  String kcm = request.getParameter("kcm").replace(" ", "");
		  String js  = request.getParameter("js");
		  String jxl = request.getParameter("jxl");
		  String sj  =request.getParameter("sj");
		  String xf = request.getParameter("xf");
		  //System.out.println(id+"---"+kcm+"---"+js+"---"+jxl+"---"+sj+"---"+xf);
		  kUser kuser = new kUser();
		  kuser.setK_id(Integer.parseInt(id));
		  kuser.setK_kcm(kcm);
		  kuser.setK_js(js);
		  kuser.setK_jxl(Integer.parseInt(jxl));
		  kuser.setK_sj(sj);
		  kuser.setK_xf(Integer.parseInt(xf));
         new userDao().updatekUser(kuser);   
	}
	
	private void delectkUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		  String id  =request.getParameter("id");
	   	  kUser kuser = new kUser();
	   	  kuser.setK_id(Integer.parseInt(id));
         new userDao().deletekUser(kuser);  
	}
	private void allkUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		List<kUser> kuser=new userDao().getAllkUser();
		request.getSession().setAttribute("bgkUser", kuser);
		request.getRequestDispatcher("/background.jsp").forward(request, response);   
	}

}
最近下载更多
hongdongdong  LV13 5月7日
asddwh  LV12 2023年12月26日
2036495585  LV9 2023年9月25日
qwqwqw12345  LV3 2023年6月20日
ppooppoo932  LV4 2023年6月7日
1WQAQW1  LV2 2023年6月7日
qiangmin1223  LV12 2023年4月24日
KrisNo10000  LV2 2023年3月1日
linkai8165  LV8 2023年1月30日
微信网友_6248713511227392  LV11 2022年12月5日
最近浏览更多
慵懒的小橘猫  LV11 6月8日
wangbh1234  LV1 6月7日
hyt123456  LV3 5月9日
op123129 4月15日
暂无贡献等级
Lilei66 3月27日
暂无贡献等级
logan123 3月17日
暂无贡献等级
222dsff 1月5日
暂无贡献等级
asddwh  LV12 2023年12月26日
WBelong  LV7 2023年12月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友