首页 前端知识 基于javaweb mysql的jsp servlet人事hr管理系统(java servlet jsp jquery easyui ztree mysql)

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

2024-01-24 15:01:56 前端知识 前端哥 516 535 我要收藏

基于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
        jscode += "&nbsp;&nbsp;<input type=text readonly style='border:0px' size=30  name=\"docname\" id=\"docname\" value=\"\" />";
        return jscode;
    }

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

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

    public static String tform(HashMap map, String formname) {
        String jscode = "";
        try {
            jscode += "<script type=\"text/javascript\">\n";
            jscode += "function getPvalue()\n";
            jscode += "{\n";

            Set set = map.entrySet();
            Iterator it = set.iterator();
            while (it.hasNext()) {
                String pm = ((Object) it.next()).toString();
                String str1 = "";
                String str2 = "";
                String[] strs = pm.split("=");
                str1 = strs[0];
                if (strs.length == 1) str2 = "";
                if (strs.length == 2) str2 = strs[1];
                str2 = str2.replaceAll("\r\n", "---");
                // str2 = str2.replaceAll("\"", "'");

                if (!str1.equals("content")) {

                    jscode += " if(document.getElementsByName(\"" + str1 + "\").length>1)\n";
                    jscode += " {\n";
                    jscode += " var radios = document.getElementsByName(\"" + str1 + "\");\n";

                    jscode += " if(radios[0].type=='radio'){\n";
                    jscode += " for(var i=0;i<radios.length;i++)\n";
                    jscode += " {\n";
            cols += str.split("-")[0] + ",";
        }
        cols = cols.substring(0, cols.length() - 1);
        String where = request.getAttribute("where") == null ? "" : request.getAttribute("where").toString();
        List<List> mlist = new CommDAO().selectforlist("select " + cols + " from " + fileName + " " + where + "  order by id desc");

        fileName = request.getRealPath("/") + "/upfile/" + Info.generalFileName("a.xls");
        String[] pros = prosstr.split("@");
        try {
            //首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
            wwb = Workbook.createWorkbook(new File(fileName));
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (wwb != null) {
            //创建一个可写入的工作表
            //Workbook的createSheet方法有两个参数,第一个是工作表的名称,第二个是工作表在工作薄中的位置
            WritableSheet ws = wwb.createSheet("sheet1", 0);
            ws.setColumnView(0, 20);
            ws.setColumnView(1, 20);
            ws.setColumnView(2, 20);
            ws.setColumnView(3, 20);
            ws.setColumnView(4, 20);
            ws.setColumnView(5, 20);

            try {

                for (int i = 0; i < pros.length; i++) {
                    Label label1 = new Label(i, 0, "");

                    label1.setString(pros[i]);
                    ws.addCell(label1);
                }

            } catch (RowsExceededException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (WriteException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            //下面开始添加单元格
    public static String getImgUpInfo3(int height) {
        String jscode = "";
        jscode += "<img style=\"cursor: hand\" οnclick=\"uploadimg3()\" src=\"js/nopic.jpg\" id=txt3 height=\"" + height + "\"/>";
        jscode += "<input type=hidden name=\"filename3\" id=\"filename3\" value=\"\" />";
        return jscode;
    }

    public static String getImgUpInfo4(int height) {
        String jscode = "";
        jscode += "<img style=\"cursor: hand\" οnclick=\"uploadimg4()\" src=\"js/nopic.jpg\" id=txt4 height=\"" + height + "\"/>";
        jscode += "<input type=hidden name=\"filename4\" id=\"filename4\" value=\"\" />";
        return jscode;
    }

    public static String getImgUpInfo5(int height) {
        String jscode = "";
        jscode += "<img style=\"cursor: hand\" οnclick=\"uploadimg5()\" src=\"js/nopic.jpg\" id=txt5 height=\"" + height + "\"/>";
        jscode += "<input type=hidden name=\"filename5\" id=\"filename5\" value=\"\" />";
        return jscode;
    }

    public static String fck(int height, String content) {
        String jscode = "<TEXTAREA   name=\"content\" id=\"content\">" + content + "</TEXTAREA>";
        jscode += "<script language=\"javascript\">";
        jscode += "function fckinit()";
        jscode += "{";
        jscode += " var of = new FCKeditor(\"content\");";
        jscode += "of.BasePath=\"fckeditor/\";";
        jscode += "of.Height = \"" + height + "\";";
        jscode += "of.ToolbarSet=\"Default\";";
        jscode += "of.ReplaceTextarea();";
        jscode += "}";
        jscode += "fckinit();";
        jscode += "</script>";

        return jscode;
    }

    public synchronized static String subStr(String source, int length) {
        if (source.length() > length) {
            source = source.substring(0, length) + "...";
        }


    public static String getImgUpInfo3(int height) {
        String jscode = "";
        jscode += "<img style=\"cursor: hand\" οnclick=\"uploadimg3()\" src=\"js/nopic.jpg\" id=txt3 height=\"" + height + "\"/>";
        jscode += "<input type=hidden name=\"filename3\" id=\"filename3\" value=\"\" />";
        return jscode;
    }

    public static String getImgUpInfo4(int height) {
        String jscode = "";
        jscode += "<img style=\"cursor: hand\" οnclick=\"uploadimg4()\" src=\"js/nopic.jpg\" id=txt4 height=\"" + height + "\"/>";
        jscode += "<input type=hidden name=\"filename4\" id=\"filename4\" value=\"\" />";
        return jscode;
    }

    public static String getImgUpInfo5(int height) {
        String jscode = "";
        jscode += "<img style=\"cursor: hand\" οnclick=\"uploadimg5()\" src=\"js/nopic.jpg\" id=txt5 height=\"" + height + "\"/>";
        jscode += "<input type=hidden name=\"filename5\" id=\"filename5\" value=\"\" />";
        return jscode;
    }

    public static String fck(int height, String content) {
        String jscode = "<TEXTAREA   name=\"content\" id=\"content\">" + content + "</TEXTAREA>";
        jscode += "<script language=\"javascript\">";
        jscode += "function fckinit()";
        jscode += "{";
        jscode += " var of = new FCKeditor(\"content\");";
        jscode += "of.BasePath=\"fckeditor/\";";
        jscode += "of.Height = \"" + height + "\";";
        jscode += "of.ToolbarSet=\"Default\";";
        jscode += "of.ReplaceTextarea();";
        jscode += "}";
        jscode += "fckinit();";
        jscode += "</script>";

        return jscode;
    }

    public synchronized static String subStr(String source, int length) {
        if (source.length() > length) {
            source = source.substring(0, length) + "...";
                System.out.println(sql);
                this.commOper(sql);

                st.close();

            } catch (SQLException e) {
                e.printStackTrace();
            }
            String str = "";
            if (!reflush)
                str += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \n";
            str += "<script language=javascript>\n";
            if (alert) {
                str += "alert('操作成功');\n";
            }
            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>";

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

        return "";
    }

    public void delete(HttpServletRequest request, String tablename) {

        int i = 0;
        try {
                        }
                    } else {
                        if (typemap.get(str + "---").equals("int")) {
                            sql += (extmap.get(str) == null ? "" : extmap.get(str)) + ",";
                        } else {
                            sql += "'" + (extmap.get(str) == null ? "" : extmap.get(str)) + "',";
                        }
                    }
                }

                sql = sql.substring(0, sql.length() - 1) + ")";
                System.out.println(sql);
                this.commOper(sql);

                st.close();

            } catch (SQLException e) {
                e.printStackTrace();
            }
            String str = "";
            if (!reflush)
                str += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \n";
            str += "<script language=javascript>\n";
            if (alert) {
                str += "alert('操作成功');\n";
            }
            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>";

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

        return "";
    }

    public void delete(HttpServletRequest request, String tablename) {

                            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
    }
}
package dao;

    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) {
            e.printStackTrace();
        }
    }

    public void gor(String url, HttpServletRequest request, HttpServletResponse response) {
        try {
            response.sendRedirect(url);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String ac = request.getParameter("ac");
        if (ac == null) ac = "";
        CommDAO dao = new CommDAO();
        String date = Info.getDateStr();
        String today = date.substring(0, 10);
        String tomonth = date.substring(0, 7);

        if (ac.equals("login")) {
            String username = request.getParameter("username");

/**
 * @description:
 */
public class CommDAO {
    public static String dbname = "";
    public static String dbtype = "";

    public static Connection conn = null;

    public CommDAO() {
        conn = this.getConn();
    }

    //给字段做加减法
    public void jiajian(String tablename, String colname, String id, String num) {
        HashMap map = this.getmap(id, tablename);
        String value = map.get(colname).toString();
        if (value.equals("")) value = "0";
        int i = Integer.parseInt(value);
        int j = Integer.parseInt(num);
        commOper("update " + tablename + " set " + colname + " = " + (i + j) + " where id=" + id);
    }

    //	该方法返回一个table 用于流动图片
    public String DynamicImage(String categoryid, int cut, int width, int height) {
                if (end == -1) {
                    done = false;
                }
            } else {
                end = end + to.length();
                subLowcase2 = sourceLowcase.substring(end, source.length());
                sub2 = source.substring(end, source.length());
                sourceLowcase = subLowcase1 + subLowcase2;
                source = sub1 + sub2;
            }
            //System.out.println(start+" "+end);
        }
        return source;
    }

    public static void delPic(String path, String img) {
        if (img != null) {
            if (!img.equals("")) {
                File file1 = new File(path + "/" + img);
                if (file1.exists()) {
                    //file1.deleteOnExit();
                    //file1.delete();
                }
            }
        }
    }

}

		

package control;

                    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);
            } 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();
                            }

            radio += "<label><input type='radio' name='" + name + "' " + check + " value=\"" + optionstr + "\">" + optionstr + "</label>\n";
            dxii++;
        }
        return radio;
    }

    public static void writeExcel(String fileName, String prosstr, java.util.List<List> plist, HttpServletRequest request, HttpServletResponse response) {
        WritableWorkbook wwb = null;
        String cols = "";
        for (String str : prosstr.split("@")) {
            cols += str.split("-")[0] + ",";
        }
        cols = cols.substring(0, cols.length() - 1);
        String where = request.getAttribute("where") == null ? "" : request.getAttribute("where").toString();
        List<List> mlist = new CommDAO().selectforlist("select " + cols + " from " + fileName + " " + where + "  order by id desc");

        fileName = request.getRealPath("/") + "/upfile/" + Info.generalFileName("a.xls");
        String[] pros = prosstr.split("@");
        try {
            //首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
            wwb = Workbook.createWorkbook(new File(fileName));
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (wwb != null) {
            //创建一个可写入的工作表
            //Workbook的createSheet方法有两个参数,第一个是工作表的名称,第二个是工作表在工作薄中的位置
            WritableSheet ws = wwb.createSheet("sheet1", 0);
            ws.setColumnView(0, 20);
            ws.setColumnView(1, 20);
            ws.setColumnView(2, 20);
            ws.setColumnView(3, 20);
            ws.setColumnView(4, 20);
            ws.setColumnView(5, 20);

            try {

                for (int i = 0; i < pros.length; i++) {
                    Label label1 = new Label(i, 0, "");

                    label1.setString(pros[i]);
                    ws.addCell(label1);
                }

            }
            sesuu += t[i] + "-";
        }

        return sesuu.substring(0, 10);
    }

    /**
     * 计算两个时期之间的天数
     */
    public static int dayToday(String DATE1, String DATE2) {
        int i = 0;
        if (DATE1.indexOf(" ") > -1)
            DATE1 = DATE1.substring(0, DATE1.indexOf(" "));
        if (DATE2.indexOf(" ") > -1)
            DATE2 = DATE2.substring(0, DATE2.indexOf(" "));

        String[] d1 = DATE1.split("-");
        if (d1[1].length() == 1) {
            DATE1 = d1[0] + "-0" + d1[1];
        } else {
            DATE1 = d1[0] + "-" + d1[1];
        }

        if (d1[2].length() == 1) {
            DATE1 = DATE1 + "-0" + d1[2];
        } else {
            DATE1 = DATE1 + "-" + d1[2];
        }

        String[] d2 = DATE2.split("-");
        if (d2[1].length() == 1) {
            DATE2 = d2[0] + "-0" + d2[1];
        } else {
            DATE2 = d2[0] + "-" + d2[1];
        }

        if (d2[2].length() == 1) {
            DATE2 = DATE2 + "-0" + d2[2];
        } else {
            DATE2 = DATE2 + "-" + d2[2];
        }

        for (int j = 0; j < 10000; j++) {
            i = j;
            String gday = Info.getDay(DATE1, j);
            if (gday.equals(DATE2)) {
                break;
            }
        }
                    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);
            } 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 {
                        }
                    }
        }

        if (ac.equals("adminlogin")) {
            String username = request.getParameter("username");
            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);

    public static String getcheckbox(String name, String tablename, String zdname, String where) {
        String checkbox = "";
        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);

            checkbox += "<label><input type='checkbox' name='" + name + "' value=\"" + optionstr + "\">" + optionstr + "</label>\n";
        }
        checkbox += "<input type=hidden name='" + name + "' value='' />";
        return checkbox;
    }

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

            String optionstr = "'";
            for (String str : zdname.split(";")) {
                if (str.indexOf("~") > -1) {
                    String zdstr = str.split("~")[0];
                    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")) {
        jscode += "of.ToolbarSet=\"Default\";";
        jscode += "of.ReplaceTextarea();";
        jscode += "}";
        jscode += "fckinit();";
        jscode += "</script>";

        return jscode;
    }

    public synchronized static String subStr(String source, int length) {
        if (source.length() > length) {
            source = source.substring(0, length) + "...";
        }

        return source;
    }

    public synchronized static String ensubStr(Object source, int length) {
        String msource = Info.filterStrIgnoreCase(source.toString(), "<", ">");
        if (msource.length() > length) {
            msource = msource.substring(0, length) + "...";
        }
        return msource;
    }

    public static String getDateStr() {
        String dateString = "";
        try {//yyyyMMddHHmmss
            java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            java.util.Date currentTime_1 = new java.util.Date();
            dateString = formatter.format(currentTime_1);
        } catch (Exception e) {
        }
        return dateString;
    }

    public static String getUTFStr(String str) {
        if (str == null) {
            return "";
                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/uploadimg3.jsp?filename=" + filename, request, response);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

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

                    DiskFileItemFactory factory = new DiskFileItemFactory();
            if (!(((String) m.get("mima")).equals(olduserpass))) {
                request.setAttribute("error", "");
                go("mod2.jsp", request, response);
            } else {
                //String id = (String)user.get("id");
                String sql = "update yonghuzhuce set mima='" + userpass + "' where yonghuming='" + (String) request.getSession().getAttribute("username") + "'";
                dao.commOper(sql);
                request.setAttribute("suc", "");
                go("mod2.jsp", request, response);
            }
        }

        if (ac.equals("adminuppass")) {
            String olduserpass = request.getParameter("ymm");
            String userpass = request.getParameter("xmm1");
            String copyuserpass = request.getParameter("xmm2");
            //println(Info.getUser(request).get("id").toString());
            HashMap m = dao.getmaps("username", (String) request.getSession().getAttribute("username"), "allusers");

            if (!(((String) m.get("pwd")).equals(olduserpass))) {
                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 {

/**
 */
public class PageManager {
    private PageManager() {

    }

    // 默认一页最大记录数
    public static final int DEFAULTPAGESIZE = 20;

    // 分页段
    public static final int segment = 10;

    // 当前页数
    protected int currentPage;

    // 一页长度
    protected int pageSize;

    // 总页数
    protected long pageNumber;

    // 总记录数
    protected long count;

    // 数据
    protected Collection collection;

    // 数据查询对象
    protected CommDAO dao = new CommDAO();

    // 表现层代码
    protected String info;

    // 请求路径
    protected String path;

    // 服务器请求对象
    protected HttpServletRequest request;

            }
        }

        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);
            } 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);
                    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();
            }
        }

        if (ac.equals("uploaddoc3")) {
            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) {
            re.printStackTrace();
            throw re;
        }

        return mlist;
    }

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

/**
 */
public class PageManager {
    private PageManager() {

    }

    // 默认一页最大记录数
    public static final int DEFAULTPAGESIZE = 20;

    // 分页段
    public static final int segment = 10;

    // 当前页数
    protected int currentPage;

    // 一页长度
    protected int pageSize;

    // 总页数
    protected long pageNumber;

    // 总记录数
    protected long count;

    // 数据
            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);
            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();
                        .getSession().getAttribute("currentPage"));

            } catch (Exception e1) {
                this.currentPage = 1;

            }
        }
    }

    /**
     *
     */
    public static PageManager getPage(String path, int pageSize,
                                      HttpServletRequest request) {
        return new PageManager(path, pageSize, request);
    }

    /**
     *
     *
     *
     */
    public void doList(String hql) {

        this.count = this.dao.select(hql).size();
        if (this.count != 0) {
            this.pageNumber = count % this.pageSize == 0 ? this.count
                    / this.pageSize : this.count / this.pageSize + 1;
            if (this.currentPage > this.pageNumber)
                this.currentPage = (int) this.pageNumber;

        }
        this.request.getSession().setAttribute("currentPage",
                String.valueOf(this.currentPage));
        this.collection = this.dao.select(hql,
                this.currentPage , this.pageSize);

        this.refreshUrl();
    }

    /**
     *
     *  如没有条件只是列表就不使用这个方法
     */
            ResultSet rs = st.executeQuery(sql);
            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

            if (sql.equals("show tables"))
                list = select("select table_name from INFORMATION_SCHEMA.tables");
            else
                e.printStackTrace();
        }
        return list;
    }

    public List<List> selectforlist(String sql) {
        List<List> list = new ArrayList();
        try {
            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));
                }

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

转载请注明出处或者链接地址:https://www.qianduange.cn//article/253.html
标签
mysqlmaven
评论
发布的文章

JSON&yaml和Properties

2024-06-06 10:06:54

JavaScript中的JSON.stringify()

2024-06-06 10:06:52

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!