基于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项目
技术栈
- 后端:Servlet 2. 前端:JSP+css+javascript+jQuery+easyUI+ztree
使用说明
- 使用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
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
response.sendRedirect("upload?filename=" + fileName.substring(fileName.lastIndexOf("/") + 1));
} catch (IOException e) {
e.printStackTrace();
}
}
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);
}
} 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");
String password = request.getParameter("pwd1");
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("/index.jsp", request, response);
} else {
String sql1 = "";
} else {
sql1 = "select * from yuangongxinxi where gonghao='" + username + "' and mima='" + password + "'";
}
List<HashMap> userlist1 = dao.select(sql1);
if (userlist1.size() == 1) {
request.getSession().setAttribute("username", userlist1.get(0).get("yonghuming"));
} else {
request.getSession().setAttribute("username", userlist1.get(0).get("gonghao"));
}
request.getSession().setAttribute("cx", utype);
gor("index.jsp", request, response);
} else {
request.setAttribute("error", "");
go("/index.jsp", request, response);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
}
}
}
go("/js/uploadimg.jsp?filename=" + filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if (ac.equals("uploadimg2")) {
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/uploadimg2.jsp?filename=" + filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
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();
}
}
}
}
}
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) + "...";
}
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;
}
}
/**
* @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);
int i = rsmd.getColumnCount();
System.out.println(i);
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));
if (names.indexOf("," + rsmd.getColumnName(j) + ",") > -1) {
String[] values = request.getParameterValues(rsmd.getColumnName(j));
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-" + rsmd.getColumnName(j) + "-value") != null) {
String dkv = request.getParameter(vstr);
String dknamevalue = request.getParameter("dk-" + rsmd.getColumnName(j) + "-value");
vstr += " - " + dknamevalue + ":" + dkv;
System.out.println(vstr);
}
//if(vstr.length()<)
value += vstr + " ~ ";
}
if (value == null) value = "";
if (value.equals("null")) value = "";
if (value.length() > 0) value = value.substring(0, value.length() - 3);
if (rsmd.getColumnTypeName(j).equals("int")) {
sql += rsmd.getColumnName(j) + "=" + value + ",";
} else {
sql += rsmd.getColumnName(j) + "='" + value + "',";
}
} else {
if (extmap.get(rsmd.getColumnName(j)) != null) {
if (rsmd.getColumnTypeName(j).equals("int")) {
sql += rsmd.getColumnName(j) + "=" + extmap.get(rsmd.getColumnName(j)) + ",";
} else {
sql += rsmd.getColumnName(j) + "='" + extmap.get(rsmd.getColumnName(j)) + "',";
}
}
}
}
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
if (rs.next()) {
i = rs.getInt(1);
}
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return i;
}
public double getDouble(String sql) {
double i = 0;
try {
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
if (rs.next()) {
i = rs.getDouble(1);
}
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
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++) {
// 总页数
protected long pageNumber;
// 总记录数
protected long count;
// 数据
protected Collection collection;
// 数据查询对象
protected CommDAO dao = new CommDAO();
// 表现层代码
protected String info;
// 请求路径
protected String path;
// 服务器请求对象
protected HttpServletRequest request;
/*
* 仅仅只是加到路径中去
*/
protected String parameter = "";
protected PageManager(String path, int pageSize, HttpServletRequest request) {
// 任意一个dao都行
this.currentPage = 1;
this.pageNumber = 1;
this.count = 0;
this.pageSize = pageSize <= 0 ? DEFAULTPAGESIZE : pageSize;
this.request = request;
this.path = path;
request.setAttribute("page", this);
try {
this.currentPage = Integer.parseInt(request
.getParameter("currentPage")) <= 0 ? 1 : Integer
.parseInt(request.getParameter("currentPage"));
} catch (Exception e) {
try {
this.currentPage = Integer.parseInt((String) request
.getSession().getAttribute("currentPage"));
} catch (Exception e1) {
this.currentPage = 1;
}
}
}
try {
filename = new String(filename.getBytes("gb2312"), "ISO8859-1");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0){
try {
filename = URLEncoder.encode(filename, "gb2312");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
}
}
response.setContentType("text/plain");
response.setHeader("Location",filename);
response.reset();
response.setHeader("Cache-Control", "max-age=0" );
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
try {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
// File f = new File(request.getRealPath("/upfile/")+"/"+filename);
//System.out.println(f);
bis = new BufferedInputStream((InputStream)new FileInputStream(request.getRealPath("/upfile/")+"/"+filename));
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos);
int bytesRead = 0;
byte[] buffer = new byte[5 * 1024];
while ((bytesRead = bis.read(buffer)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
bis.close();
fos.close();
new Info().delPic(request.getRealPath("/upfile/")+"/", filename);
} catch (Exception e) {
}finally{
}
}
/**
String title = Info.subStr(b.get("biaoti").toString(), 21);
String url = "" + b.get("shouyetupian");
String purl = "nxiang.jsp?id=" + b.get("id");
if (j != i) {
thePics1.append(url.replaceAll("\n", "") + "|");
theLinks1.append(purl + "|");
theTexts1.append(title + "|");
}
if (j == i) {
thePics1.append(url.replaceAll("\n", ""));
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);
commOper("update " + tablename + " set " + colname + " = " + (i + j) + " where id=" + id);
}
// 该方法返回一个table 用于流动图片
public String DynamicImage(String categoryid, int cut, int width, int height) {
StringBuffer imgStr = new StringBuffer();
StringBuffer thePics1 = new StringBuffer();
StringBuffer theLinks1 = new StringBuffer();
StringBuffer theTexts1 = new StringBuffer();
imgStr.append("<div id=picViwer1 style='background-color: #ffffff' align=center></div><SCRIPT src='js/dynamicImage.js' type=text/javascript></SCRIPT>\n<script language=JavaScript>\n");
thePics1.append("var thePics1=\n'");
theLinks1.append("var theLinks1='");
theTexts1.append("var theTexts1='");
List<HashMap> co = this.select("select * from xinwentongzhi where shouyetupian<>'' and shouyetupian<>'null' and shouyetupian like '%.jpg' order by id desc", 1, 6);
int i = co.size();
int j = 0;
for (HashMap b : co) {
j++;
int id = Integer.parseInt(b.get("id").toString());
String title = Info.subStr(b.get("biaoti").toString(), 21);
String url = "" + b.get("shouyetupian");
String purl = "nxiang.jsp?id=" + b.get("id");
if (j != i) {
thePics1.append(url.replaceAll("\n", "") + "|");
theLinks1.append(purl + "|");
theTexts1.append(title + "|");
}
if (j == i) {
thePics1.append(url.replaceAll("\n", ""));
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();
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/uploadimg.jsp?filename=" + filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if (ac.equals("uploadimg2")) {
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 {
}
}
}
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";
jscode += " if(radios[i].value==\"" + str2 + "\")\n";
jscode += " {\n";
jscode += " radios[i].checked=\"checked\";\n";
jscode += " }\n";
jscode += " }\n";
jscode += " }\n";
jscode += " if(radios[0].type=='checkbox'){\n";
jscode += " for(var i=0;i<radios.length;i++)\n";
jscode += " {\n";
jscode += " if(\"" + str2 + "\".indexOf(radios[i].value)>-1&&radios[i].id.indexOf('choosebox')==-1)\n";
jscode += " {\n";
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");
String password = request.getParameter("pwd1");
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("/index.jsp", request, response);
} else {
String sql1 = "";
this.path).append("¤tPage='+").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;
}
public int getPageSize() {
return pageSize;
}
public String getInfo() {
return info;
}
public static ArrayList<HashMap> getPages(String url, int pagesize, String sql, HttpServletRequest request )
{
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();