基于javaweb+mysql的jsp+servlet人事hr管理系统(java+servlet+jsp+jquery+easyui+ztree+mysql)

基于javaweb+mysql的jsp+servlet人事hr管理系统(java+servlet+jsp+jquery+easyui+ztree+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的JSP+Servlet人事HR管理系统(java+servlet+jsp+jquery+easyui+ztree+mysql)

项目介绍

本项目为基于jsp的HR人事管理系统,可以完美运行。 主要分为超级管理员与普通管理员两种角色; 管理员主要功能包括: 系统管理员:管理员管理、修改密码; 部门信息管理:部门信息添加、部门信息查询; 员工信息管理:新员工登记、员工信息查询; 合同信息管理:合同信息添加、合同信息查询; 考勤信息管理:员工请假信息查询审核、考勤信息添加、考勤信息查询; 工资信息管理:工资信息添加、工资信息查询; 应聘信息管理:应聘信息添加、应聘信息查询; 调职信息管理:调职信息添加、调职信息查询; 离职信息管理:离职信息添加、离职信息查询; 复职信息管理:复职信息添加、复职信息查询; 系统管理; 普通管理员无法对管理员账号信息修改,其它功能类似;

环境需要

1.运行环境:java jdk 1.7;注:本项目目前仅支持jdk 1.7; 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7、8.0等版本均可; 6.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

技术栈

  1. 后端:Servlet 2. 前端:JSP+css+javascript+jQuery+easyUI+ztree

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/login.jsp 登录 超级管理员账号密码:hsg/hsg 普通管理员账号密码:ldx/ldx
        // } else {
        // buf.append("<a href='").append(this.path).append(
        // "&currentPage=").append(i + 1).append(parameter)
        // .append("' style='TEXT-DECORATION:none'>").append(
        // "[" + (i + 1) + "]").append("</a>&nbsp;");
        // }

        // }
        buf.append("<select οnchange=\"javascript:window.location='").append(
                        this.path).append("&currentPage='+").append(
                        "this.options[this.selectedIndex].value").append(parameter)
                .append("\">");
        for (int i = 0; i < this.pageNumber; i++) {
            if (this.currentPage == i + 1)
                buf.append("<option value=" + (i + 1)
                        + " selected=\"selected\">" + (i + 1) + "</option>");
            else
                buf.append("<option value=" + (i + 1) + ">" + (i + 1)
                        + "</option>");

        }
        buf.append("</select>");
        this.info = buf.toString();

    }

    public Collection getCollection() {
        return collection;
    }

    public long getCount() {
        return count;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public long getPageNumber() {
        return pageNumber;
    }
            String password = request.getParameter("pwd");
            String utype = request.getParameter("cx");
            String pagerandom = request.getParameter("pagerandom") == null ? "" : request.getParameter("pagerandom");
            String random = (String) request.getSession().getAttribute("random");
            if (!pagerandom.equals(random) && request.getParameter("a") != null) {
                request.setAttribute("random", "");
                go("/login.jsp", request, response);
            } else {
                String sql1 = "";
                    sql1 = "select * from yuangongxinxi where yuangongbianhao='" + username + "' and mima='" + password + "'";
                } else {
                        sql1 = "select * from bumenjingli where bumenbianhao='" + username + "' and mima='" + password + "'";

                    } else {
                        sql1 = "select * from allusers where username='" + username + "' and pwd='" + password + "'";
                    }
                }

                List<HashMap> userlist1 = dao.select(sql1);
                if (userlist1.size() == 1) {
                        request.getSession().setAttribute("username", userlist1.get(0).get("yuangongbianhao"));
                        request.getSession().setAttribute("cx", utype);
                    } else {
                            request.getSession().setAttribute("username", userlist1.get(0).get("bumenbianhao"));
                            request.getSession().setAttribute("cx", utype);

                        } else {
                            request.getSession().setAttribute("username", userlist1.get(0).get("username"));
                            request.getSession().setAttribute("cx", userlist1.get(0).get("cx"));
                        }
                    }

                    gor("main.jsp", request, response);
                } else {
                    request.setAttribute("error", "");
                    go("/login.jsp", request, response);
                }
            }
        }

                request.setAttribute("error", "");
                go("mod.jsp", request, response);
            } else {
                //String id = (String)user.get("id");
                String sql = "update allusers set pwd='" + userpass + "' where username='" + (String) request.getSession().getAttribute("username") + "'";
                dao.commOper(sql);
                request.setAttribute("suc", "");
                go("mod.jsp", request, response);
            }
        }

        if (ac.equals("uploaddoc")) {
            try {
                String filename = "";
                request.setCharacterEncoding("gb2312");
                RequestContext requestContext = new ServletRequestContext(request);
                if (FileUpload.isMultipartContent(requestContext)) {

                    DiskFileItemFactory factory = new DiskFileItemFactory();
                    factory.setRepository(new File(request.getRealPath("/upfile/") + "/"));
                    ServletFileUpload upload = new ServletFileUpload(factory);
                    upload.setSizeMax(100 * 1024 * 1024);
                    List items = new ArrayList();

                    items = upload.parseRequest(request);

                    FileItem fileItem = (FileItem) items.get(0);
                    if (fileItem.getName() != null && fileItem.getSize() != 0) {
                        if (fileItem.getName() != null && fileItem.getSize() != 0) {
                            File fullFile = new File(fileItem.getName());
                            filename = Info.generalFileName(fullFile.getName());
                            File newFile = new File(request.getRealPath("/upfile/") + "/" + filename);
                            try {
                                fileItem.write(newFile);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                        }
                    }
                }

                go("/js/uploaddoc.jsp?docname=" + filename, request, response);
        return i;
    }

    public void commOper(String sql) {
        System.out.println(sql);
        try {
            Statement st = conn.createStatement();
            st.execute(sql);
            st.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void commOperSqls(ArrayList<String> sql) {

        try {
            conn.setAutoCommit(false);
            for (int i = 0; i < sql.size(); i++) {
                Statement st = conn.createStatement();
                System.out.println(sql.get(i));
                st.execute(sql.get(i));
                st.close();
            }
            conn.commit();
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        } finally {
            try {
                conn.setAutoCommit(true);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public List<HashMap> select(String sql) {
        System.out.println(sql);
        List<HashMap> list = new ArrayList();
        try {
                    factory.setRepository(new File(request.getRealPath("/upfile/") + "/"));
                    ServletFileUpload upload = new ServletFileUpload(factory);
                    upload.setSizeMax(100 * 1024 * 1024);
                    List items = new ArrayList();

                    items = upload.parseRequest(request);

                    FileItem fileItem = (FileItem) items.get(0);
                    if (fileItem.getName() != null && fileItem.getSize() != 0) {
                        if (fileItem.getName() != null && fileItem.getSize() != 0) {
                            File fullFile = new File(fileItem.getName());
                            filename = Info.generalFileName(fullFile.getName());
                            File newFile = new File(request.getRealPath("/upfile/") + "/" + filename);
                            try {
                                fileItem.write(newFile);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                        }
                    }
                }

                go("/js/uploadimg5.jsp?filename=" + filename, request, response);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

        dao.close();
        out.flush();
        out.close();
    }

    public void init() throws ServletException {
        // Put your code here
    }
}

						"]</a>");
		}*/

        buf.append("&nbsp;&nbsp;");
        if (this.currentPage < this.pageNumber) {
            buf.append("<a href='").append(this.path).append("&currentPage=")
                    .append(currentPage + 1).append(parameter).append(
                            "' class='ls'>").append("Next")
                    .append("</a>");
        } else {

            buf.append("Next");
        }

        buf.append("&nbsp;&nbsp;&nbsp;&nbsp;");
        if (this.currentPage == this.pageNumber)
            buf.append("Last&nbsp;&nbsp;");
        else
            buf.append("<a href='").append(this.path).append("&currentPage=")
                    .append(this.pageNumber).append(parameter).append(
                            "' class='ls'>").append("Last")
                    .append("</a></font>&nbsp;&nbsp;");
        // 
        // for (int i = 0; i < this.pageNumber; i++) {
        // if (this.currentPage == i + 1) {
        // buf.append("<font color=red>[" + (i + 1) + "]</font>").append(
        // "&nbsp;");
        // } else {
        // buf.append("<a href='").append(this.path).append(
        // "&currentPage=").append(i + 1).append(parameter)
        // .append("' style='TEXT-DECORATION:none'>").append(
        // "[" + (i + 1) + "]").append("</a>&nbsp;");
        // }

        // }
        buf.append("<select οnchange=\"javascript:window.location='").append(
                        this.path).append("&currentPage='+").append(
                        "this.options[this.selectedIndex].value").append(parameter)
                .append("\">");
        for (int i = 0; i < this.pageNumber; i++) {
            if (this.currentPage == i + 1)
                buf.append("<option value=" + (i + 1)
                        + " selected=\"selected\">" + (i + 1) + "</option>");
            else
                buf.append("<option value=" + (i + 1) + ">" + (i + 1)
                        + "</option>");

        }
        buf.append("</select>");
        this.info = buf.toString();

    }

    public Collection getCollection() {

            jscode += " getPvalue();\n";
            jscode += "</script>\n";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jscode;
    }

    public static String generalFileName(String srcFileName) {
        try {
            int index = srcFileName.lastIndexOf(".");
            return StrUtil.generalSrid() + srcFileName.substring(index).toLowerCase();
        } catch (Exception e) {
            return StrUtil.generalSrid();
        }
    }

    public synchronized static String getID() {

        Random random = new Random();
        StringBuffer ret = new StringBuffer(20);
        java.util.Date date = new java.util.Date();
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("MMddHHmmss", java.util.Locale.CHINA);
        ret.append(format.format(date));
        String rand = String.valueOf(Math.abs(random.nextInt()));
        //ret.append(getDateStr());
        ret.append(rand.substring(0, 4));

        return ret.toString();
    }

    public static String getImgUpInfo(int height) {
        String jscode = "";
        jscode += "<img style=\"cursor: pointer;margin:3px\" οnclick=\"uploadimg()\" src=\"js/nopic.jpg\" id=txt height=\"" + height + "\"/>";
        jscode += "<input type=hidden name=\"filename\" id=\"filename\" value=\"\" />";
        return jscode;
    }

    public static String getImgUpInfo2(int height) {
        String jscode = "";
        jscode += "<img style=\"cursor: hand\" οnclick=\"uploadimg2()\" src=\"js/nopic.jpg\" id=txt2 height=\"" + height + "\"/>";
        jscode += "<input type=hidden name=\"filename2\" id=\"filename2\" value=\"\" />";
        return jscode;
    }
            }
            if (tzurl.equals("")) {
                if (reflush) {
                    str += "parent.location=parent.location;\n";
                } else {
                    str += "window.location=String(window.location).replace(new RegExp('f=f', 'g'), '');";
                }
            } else {
                str += "location.href='" + tzurl + "';\n";
            }

            str += "</script>\n";

            PrintWriter wrt = null;
            try {
                //request.get
                wrt = response.getWriter();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            wrt.write(str);
        }
        return "";
    }

    public Connection getConn() {
        try {
            if (conn == null || conn.isClosed()) {

                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull",
                        "root", "123456");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

                for (int j = 1; j <= i; j++) {
                    if (rsmd.getColumnName(j).equals("id")) continue;
                    if (rsmd.getColumnName(j).equals("ID")) continue;
                    if (rsmd.getColumnName(j).equals("iD")) continue;
                    if (rsmd.getColumnName(j).equals("Id")) continue;
                    typemap.put(rsmd.getColumnName(j) + "---", rsmd.getColumnTypeName(j));
                    collist.add(rsmd.getColumnName(j));
                    sql += rsmd.getColumnName(j) + ",";
                }
                sql = sql.substring(0, sql.length() - 1);

                sql += ") values(";
                rs.close();
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            Enumeration enumeration = request.getParameterNames();
            String names = ",";
            while (enumeration.hasMoreElements()) {
                names += enumeration.nextElement().toString() + ",";
            }
            try {
                Statement st = conn.createStatement();
                for (String str : collist) {
                    if (names.indexOf("," + str + ",") > -1) {
                        String[] values = request.getParameterValues(str);
                        String value = "";
                        for (String vstr : values) {
                            if (vstr == null) vstr = "";
                            if (vstr.equals("null")) vstr = "";
                            if (vstr.trim().equals("")) continue;

                            if (request.getParameter(vstr) != null && !"".equals(request.getParameter(vstr)) && request.getParameter("dk-" + str + "-value") != null) {
                                String dkv = request.getParameter(vstr);
                                String dknamevalue = request.getParameter("dk-" + str + "-value");
                                vstr += " - " + dknamevalue + ":" + dkv;
                            }

                            value += vstr + " ~ ";

                        }
                        if (value == null) value = "";
                        if (value.equals("null")) value = "";
                        if (value.length() > 0) value = value.substring(0, value.length() - 3);

                        if (typemap.get(str + "---").equals("int")) {
                            sql += (value.equals("") ? -10 : value) + ",";
                        } else {
                            sql += "'" + (value.equals("null") ? "" : value) + "',";
                        }
                    } else {
                theLinks1.append("nxiang.jsp?id=" + b.get("id"));
                theTexts1.append(title);
            }

        }
        thePics1.append("';");

        theLinks1.append("';");
        theTexts1.append("';");
        imgStr.append(thePics1 + "\n");
        imgStr.append(theLinks1 + "\n");
        imgStr.append(theTexts1 + "\n");
        imgStr.append("\n setPic(thePics1,theLinks1,theTexts1," + width + "," + height + ",'picViwer1');</script>");
        return imgStr.toString();
    }

    public HashMap getmap(String id, String table) {
        List<HashMap> list = new ArrayList();
        try {
            Statement st = conn.createStatement();
            //System.out.println("select * from "+table+" where id="+id);
            ResultSet rs = st.executeQuery("select * from " + table + " where id=" + id);
            ResultSetMetaData rsmd = rs.getMetaData();
            while (rs.next()) {
                HashMap map = new HashMap();
                int i = rsmd.getColumnCount();
                for (int j = 1; j <= i; j++) {
                    if (!rsmd.getColumnName(j).equals("ID")) {
                        String str = rs.getString(j) == null ? "" : rs.getString(j);
                        if (str.equals("null")) str = "";
                        map.put(rsmd.getColumnName(j), str);
                    } else
                        map.put("id", rs.getString(j));
                }
                list.add(map);
            }
            rs.close();
            st.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return list.get(0);
    }

    public HashMap getmaps(String nzd, String zdz, String table) {
        List<HashMap> list = new ArrayList();
        try {
            Statement st = conn.createStatement();
            //System.out.println("select * from "+table+" where "+nzd+"='"+zdz+"'");
            ResultSet rs = st.executeQuery("select * from " + table + " where " + nzd + "='" + zdz + "'");
            ResultSetMetaData rsmd = rs.getMetaData();
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql);
            ResultSetMetaData rsmd = rs.getMetaData();

            while (rs.next()) {
                List<String> list2 = new ArrayList();
                int i = rsmd.getColumnCount();
                for (int j = 1; j <= i; j++) {
                    if (!rsmd.getColumnName(j).equals("ID")) {
                        String str = rs.getString(j) == null ? "" : rs.getString(j);
                        if (str.equals("null")) str = "";
                        list2.add(str);
                    } else
                        list2.add(rs.getString(j));
                }
                list.add(list2);
            }
            rs.close();
            st.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return list;
    }

    public void close() {

    }

    /**
     * 执行一条查询sql,以 List<hashmap> 的形式返回查询的记录,记录条数,和从第几条开始,由参数决定,主要用于翻页
     * pageno 页码  rowsize 每页的条数
     */
    public List<HashMap> select(String sql, int pageno, int rowsize) {
        List<HashMap> list = new ArrayList<HashMap>();
        List<HashMap> mlist = new ArrayList<HashMap>();
        try {
            list = this.select(sql);
    public void close() {

    }

    /**
     * 执行一条查询sql,以 List<hashmap> 的形式返回查询的记录,记录条数,和从第几条开始,由参数决定,主要用于翻页
     * pageno 页码  rowsize 每页的条数
     */
    public List<HashMap> select(String sql, int pageno, int rowsize) {
        List<HashMap> list = new ArrayList<HashMap>();
        List<HashMap> mlist = new ArrayList<HashMap>();
        try {
            list = this.select(sql);
            int min = (pageno - 1) * rowsize;
            int max = pageno * rowsize;

            for (int i = 0; i < list.size(); i++) {

                if (!(i < min || i > (max - 1))) {
                    mlist.add(list.get(i));
                }
            }
        } catch (RuntimeException re) {
            re.printStackTrace();
            throw re;
        }

        return mlist;
    }

    public static void main(String[] args) {
    }
}

/**
                    jscode += "document.getElementById(\"txt5\").src=\"upfile/" + map.get("filename5") + "\";\n";
                    jscode += "}\n";

                }
            }

            jscode += "}\n";

            jscode += " getPvalue();\n";
            jscode += "</script>\n";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jscode;
    }

    public static String generalFileName(String srcFileName) {
        try {
            int index = srcFileName.lastIndexOf(".");
            return StrUtil.generalSrid() + srcFileName.substring(index).toLowerCase();
        } catch (Exception e) {
            return StrUtil.generalSrid();
        }
    }

    public synchronized static String getID() {

        Random random = new Random();
        StringBuffer ret = new StringBuffer(20);
        java.util.Date date = new java.util.Date();
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("MMddHHmmss", java.util.Locale.CHINA);
        ret.append(format.format(date));
        String rand = String.valueOf(Math.abs(random.nextInt()));
        //ret.append(getDateStr());
        ret.append(rand.substring(0, 4));

        return ret.toString();
    }

    public static String getImgUpInfo(int height) {
        String jscode = "";
                        } else {
                        }
                    }
                }

                go("/js/uploaddoc.jsp?docname=" + filename, request, response);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

        if (ac.equals("uploaddoc2")) {
            try {
                String filename = "";
                request.setCharacterEncoding("gb2312");
                RequestContext requestContext = new ServletRequestContext(request);
                if (FileUpload.isMultipartContent(requestContext)) {

                    DiskFileItemFactory factory = new DiskFileItemFactory();
                    factory.setRepository(new File(request.getRealPath("/upfile/") + "/"));
                    ServletFileUpload upload = new ServletFileUpload(factory);
                    upload.setSizeMax(100 * 1024 * 1024);
                    List items = new ArrayList();

                    items = upload.parseRequest(request);

                    FileItem fileItem = (FileItem) items.get(0);
                    if (fileItem.getName() != null && fileItem.getSize() != 0) {
                        if (fileItem.getName() != null && fileItem.getSize() != 0) {
                            File fullFile = new File(fileItem.getName());
                            filename = Info.generalFileName(fullFile.getName());
                            File newFile = new File(request.getRealPath("/upfile/") + "/" + filename);
                            try {
                                fileItem.write(newFile);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                        }
                    }
                }

                go("/js/uploaddoc2.jsp?docname=" + filename, request, response);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
                    String zdnamestr = str.split("~")[1].equals("无名") ? "" : (str.split("~")[1] + ":");
                    optionstr += zdnamestr + permap.get(zdstr) + " - ";
                } else {
                    optionstr += permap.get(str);
                }
            }
            if (optionstr.length() > 0) optionstr = optionstr.substring(0, optionstr.length() - 3);
            optionstr += "',";
            checkbox += optionstr;
        }
        if (checkbox.length() > 0) checkbox = checkbox.substring(0, checkbox.length() - 1);

        return checkbox;
    }

    public static String getcheckboxDk(String name, String tablename, String zdname, String nstr, String where) {
        String checkbox = "";
        int i = 0;
        for (HashMap permap : new CommDAO().select("select * from " + tablename + " where " + where + " order by id desc")) {

            String optionstr = "";
            for (String str : zdname.split(";")) {
                String zdstr = str.split("~")[0];
                String zdnamestr = str.split("~")[1].equals("无名") ? "" : (str.split("~")[1] + ":");
                optionstr += zdnamestr + permap.get(zdstr) + " - ";
            }
            if (optionstr.length() > 0) optionstr = optionstr.substring(0, optionstr.length() - 3);
            String nbs = "";
            if (i > 0) nbs = "&nbsp;";
            checkbox += "<label>" + nbs + "<input type='checkbox' name='" + name + "' value=\"" + optionstr + "\">" + optionstr + "</label>&nbsp;&nbsp;\n";
            checkbox += "<label>&nbsp;- " + nstr + " &nbsp;<input type='text' size='5' name='" + optionstr + "' value=\"\"></label><br />\n";
            i++;
        }
        checkbox += "<input type=hidden name='" + name + "' value='' /><input type=hidden name='dk-" + name + "-value' value='" + nstr + "' />";
        return checkbox;
    }

    public static String getFileUpInfo() {
        String jscode = "";
        jscode += "<font οnclick=\"uploaddoc()\" src=\"js/nopic.jpg\" style='cursor:hand' id=txt >点击此处上传</font>";
        jscode += "&nbsp;&nbsp;<input type=text readonly style='border:0px' size=30  name=\"docname\" id=\"docname\" value=\"\" />";
        return jscode;
    }
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

        //导入excel
        if (ac.equals("importexcel")) {
            String page = request.getParameter("page");
            String whzdstr = request.getParameter("whzdstr");
            String tablename = request.getParameter("tablename");
            try {
                String filename = "";
                request.setCharacterEncoding("gb2312");
                RequestContext requestContext = new ServletRequestContext(request);
                if (FileUpload.isMultipartContent(requestContext)) {

                    DiskFileItemFactory factory = new DiskFileItemFactory();
                    factory.setRepository(new File(request.getRealPath("/upfile/") + "/"));
                    ServletFileUpload upload = new ServletFileUpload(factory);
                    upload.setSizeMax(100 * 1024 * 1024);
                    List items = new ArrayList();

                    items = upload.parseRequest(request);

                    FileItem fileItem = (FileItem) items.get(0);
                    if (fileItem.getName() != null && fileItem.getSize() != 0) {
                        if (fileItem.getName() != null && fileItem.getSize() != 0) {
                            File fullFile = new File(fileItem.getName());
                            filename = Info.generalFileName(fullFile.getName());
                            File newFile = new File(request.getRealPath("/upfile/") + "/" + filename);
                            try {
                                fileItem.write(newFile);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                        }
                    }

                    if (filename.indexOf(".xls") > -1) {
                        Workbook workbook;
                        try {
                            workbook = Workbook.getWorkbook(new File(request.getRealPath("/upfile/") + "/" + filename));
                            //ͨWorkbook getSheet
                            Sheet sheet = workbook.getSheet(0);
                            //Sheet getCell
                            //int empty = 0;
                            for (int i = 1; i < 1000; i++) {
                                Cell cell = null;
                        try {
                            workbook = Workbook.getWorkbook(new File(request.getRealPath("/upfile/") + "/" + filename));
                            //ͨWorkbook getSheet
                            Sheet sheet = workbook.getSheet(0);
                            //Sheet getCell
                            //int empty = 0;
                            for (int i = 1; i < 1000; i++) {
                                Cell cell = null;
                                try {
                                    String isql = "insert into " + tablename + "(";

                                    for (String str : whzdstr.split("-")) {
                                        isql += str + ",";
                                    }
                                    isql = isql.substring(0, isql.length() - 1);
                                    isql += ")values(";

                                    int j = 0;
                                    int empty = 1;
                                    for (String str : whzdstr.split("-")) {
                                        cell = sheet.getCell(j, i);
                                        isql += "'" + cell.getContents() + "',";
                                        String content = cell.getContents() == null ? "" : cell.getContents();
                                        if (!"".equals(content.trim())) {
                                            empty = 0;
                                        }
                                        j++;
                                    }
                                    if (empty == 1) continue;
                                    isql = isql.substring(0, isql.length() - 1);
                                    isql += ")";
                                    dao.commOper(isql);
                                } catch (Exception e) {
                                    continue;
                                }

                            }
                            workbook.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
                go("/admin/" + page + "?docname=" + filename, request, response);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }

}

		

public class MainCtrl extends HttpServlet {

    public MainCtrl() {
        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 {
        this.doPost(request, response);
    }

    public void go(String url, HttpServletRequest request, HttpServletResponse response) {
        try {
            request.getRequestDispatcher(url).forward(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值