package shop4;

import java.io.IOException;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
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 javax.servlet.http.HttpSession;

import dao.glyhdao;
import modo.glyh;

/**
 * Servlet implementation class gluhsvlt
 */
@WebServlet("/gluhsvlt")
public class gluhsvlt extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    

	/**
	 * @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);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pd=request.getParameter("msg");
		HttpSession session = request.getSession();
		if(pd==null){
		glyhdao a1=new glyhdao();
		List<glyh> list =new glyhdao().getlist();
		request.setAttribute("list", list);
		request.getRequestDispatcher("/staffManage/lookStaff2.jsp").forward(request, response);
		list.clear();
		
		}else if(pd.equals("tj")){
			String Name=new String(request.getParameter("staffName").getBytes("ISO-8859-1"),"UTF-8");
            String Sex=new String(request.getParameter("staffSex").getBytes("ISO-8859-1"),"UTF-8");
            String Age=new String(request.getParameter("staffAge").getBytes("ISO-8859-1"),"UTF-8");
            String Education=new String(request.getParameter("staffEducation").getBytes("ISO-8859-1"),"UTF-8");
            String Department=new String(request.getParameter("staffDepartment").getBytes("ISO-8859-1"),"UTF-8");
            String Date=new String(request.getParameter("staffDate").getBytes("ISO-8859-1"),"UTF-8");
            String Duty=new String(request.getParameter("staffDuty").getBytes("ISO-8859-1"),"UTF-8");
        	String sql="insert into staff(staffName,staffSex,staffAge,staffEducation,staffDepartment,staffDate,staffDuty,staffWage) values ('"+Name+"','"+Sex+"','"+Age+"','"+Education+"','"+Department+"','"+Date+"','"+Duty+"')";
        	glyhdao a1=new glyhdao();
        	if(a1.pdff(sql)){
        	response.sendRedirect(request.getContextPath()+"/gluhsvlt");
        	}else{
        		request.setAttribute("msg", "tj");
        		request.getRequestDispatcher("/error.jsp").forward(request, response);
        		
        	}
        	
		}else if(pd.equals("cs")){
			glyhdao a1=new glyhdao();
			String sql="DELETE FROM staff WHERE staffName='"+request.getParameter("id")+"'";
			if(a1.pdff(sql)){
	        	response.sendRedirect(request.getContextPath()+"/gluhsvlt");
	        	}else{
	        		request.setAttribute("msg", "cs");
	        		request.getRequestDispatcher("/error.jsp").forward(request, response);
	        	}
		}else if(pd.equals("xg")){
			String Name=new String(request.getParameter("xgstaffName").getBytes("ISO-8859-1"),"UTF-8");
            String Sex=new String(request.getParameter("xgstaffSex").getBytes("ISO-8859-1"),"UTF-8");
            String Age=new String(request.getParameter("xgstaffAge").getBytes("ISO-8859-1"),"UTF-8");
            String Education=new String(request.getParameter("xgstaffEducation").getBytes("ISO-8859-1"),"UTF-8");
            String Department=new String(request.getParameter("xgstaffDepartment").getBytes("ISO-8859-1"),"UTF-8");
            String Date=new String(request.getParameter("xgstaffDate").getBytes("ISO-8859-1"),"UTF-8");
            String Duty=new String(request.getParameter("xgstaffDuty").getBytes("ISO-8859-1"),"UTF-8");
        	String sql2="update staff set staffSex='"+Sex+"',staffAge='"+Age+"',staffEducation='"+Education+"',staffDepartment='"+Department+"',staffDate='"+Date+"',staffDuty='"+Duty+"' where staffName='"+Name+"'";
        	glyhdao a1=new glyhdao();
        	if(a1.pdff(sql2)){
        		
        		response.sendRedirect(request.getContextPath()+"/gluhsvlt");
        	}else{
        		request.setAttribute("msg", "xg");
        		request.getRequestDispatcher("/error.jsp").forward(request, response);
        	}
			}
		
		System.out.print(request.getParameter("id"));
		System.out.print(request.getParameter("msg"));
		System.out.print(session.getAttribute("msg"));
		/*List<glyh> glls=new ArrayList<glyh>();
			response.setContentType("text/html;charset=utf-8");
	        request.setCharacterEncoding("utf-8");
	        
	        
	        
	        
	        
           
	        try {
	            Class.forName("com.mysql.jdbc.Driver");
	        } catch (ClassNotFoundException e) {
	            e.printStackTrace();
	            System.out.println("找不到驱动 ");
	        }
	        // 连接URL                    服务器地址                       端口号    数据库名
          String url="jdbc:mysql://localhost:3306/eims?useUnicode=true&characterEncoding=gbk";
	        Connection conn = null;
	        Statement stmt = null;
	        ResultSet rs = null;
	        HttpSession session = request.getSession();
	        try {                                                    //数据可的登录名  登录密码
	            conn = (Connection) DriverManager.getConnection(url, "root", "root");
	            stmt = (Statement) conn.createStatement();
	            // SQL语句
              String sql="select * from staff";
	            rs = stmt.executeQuery(sql);// 返回查询结果
	        } catch (SQLException e) {
	            e.printStackTrace();
	        }
	        
	    //    HttpSession session = request.getSession();
	       // session.setAttribute("username", username);
	        try {
	            while(rs.next()) {
	                glls.add(new glyh(rs.getString("staffName"), rs.getString("staffSex"), rs.getString("staffAge"), rs.getString("staffEducation"), rs.getString("staffDepartment"), rs.getString("staffDate"), rs.getString("staffDuty"), rs.getString("staffWage")));
	            }
	            request.setAttribute("list", glls);
	            request.getRequestDispatcher("/staffManage/lookStaff2.jsp").forward(request, response);
	        } catch (SQLException e) {
	            e.printStackTrace();
	        }
		
	         if(request.getParameter("msg").equals("tj")){
	        	String Name=request.getParameter("staffName");
	            String Sex=request.getParameter("staffSex");
	            String Age=request.getParameter("staffAge");
	            String Education=request.getParameter("staffEducation");
	            String Department=request.getParameter("staffDepartment");
	            String Date=request.getParameter("staffDate");
	            String Duty=request.getParameter("staffDuty");
	            String Wage=request.getParameter("staffWage");
	        	String sql1="insert into staff(staffName,staffSex,staffAge,staffEducation,staffDepartment,staffDate,staffDuty,staffWage) values ('"+Name+"','"+Sex+"','"+Age+"','"+Education+"','"+Department+"','"+Date+"','"+Duty+"','"+Wage+"')";
	        	try {
					Statement stmt=null;
					stmt.executeUpdate(sql1);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				};
	        	response.sendRedirect("http://localhost:8080/shop4/glyhsvlt");	
	         	}*/
				
	        }
	}


最近下载更多
迷迭香  LV4 9月21日
gaigai211  LV2 9月13日
青梅论酒  LV9 9月6日
userli  LV4 9月5日
MingZheLi  LV2 8月28日
fanchenbai  LV2 8月25日
wanglinddad  LV51 8月20日
527502852  LV2 8月3日
王雅坤  LV3 8月2日
1q2w3e4r5t6  LV3 7月27日
最近浏览更多
迷迭香  LV4 9月21日
admin678 9月20日
暂无贡献等级
lwp011  LV27 9月19日
zhangbq 9月17日
暂无贡献等级
Ficxtion  LV2 9月16日
庭下种枇杷  LV2 9月15日
sunlzh888888  LV26 9月14日
gaigai211  LV2 9月13日
德莱文  LV14 9月13日
lilong007  LV9 9月13日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友