基于javaweb+mysql的jsp+servlet会议室预约系统(java+jsp+bootstrap+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet会议室预约系统(java+jsp+bootstrap+servlet+mysql)
项目介绍
网上会议室预约系统,该项目是一个前后台的项目;
前台主要功能有: 登录、注册; 首页、预约须知; 会议室预约; 会议室信息; 会议室预约表; 后台主要功能有: 通告栏:查看、添加、修改、删除; 会议室信息:查看、添加、修改、删除; 查看登记表; 查看预约消息;
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 6.数据库:MySql 8.0版本;
技术栈
- 后端:Servlet 2. 前端:JSP+bootstrap+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 将项目中druid.properties配置文件中的数据库配置改为自己的配置 3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行; 4. 运行项目, 前台运行地址:http://localhost:8080/index.jsp 登录 后台运行地址:http://localhost:8080/back/index.jsp 登录
@WebServlet("/regUser")
public class RegUserServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf8");
Map<String, String[]> userMap = request.getParameterMap();
User user = new User();
try {
BeanUtils.populate(user,userMap);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
UserService userService = new UserServiceImpl();
int status = userService.reqUser(user);
if(status != -1){
response.sendRedirect("login.jsp");
}else{
request.setAttribute("msg","注册失败");
request.getRequestDispatcher("req.jsp").forward(request,response);
}
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String currentPage = request.getParameter("currentPage");
RegformService regformService = new RegformServiceImpl();
int rows = 10;
int totalPage = regformService.getTotalPage(rows);
if(currentPage == null || Integer.parseInt(currentPage) < 1){
currentPage = "1";
}
if(totalPage != 0 && Integer.parseInt(currentPage) > totalPage){
currentPage = totalPage+"";
}
ListPage<RegformList> listPage = regformService.getApplyList(Integer.parseInt(currentPage),rows);
request.setAttribute("listPage",listPage);
request.getRequestDispatcher("regform.jsp").forward(request,response);
}
}
@WebServlet("/back/applyList")
public class ApplyListServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String currentPage = request.getParameter("currentPage");
ApplyService applyService = new ApplyServiceImpl();
int rows = 10;
int totalPage = applyService.getTotalPage(rows);
if(currentPage == null || Integer.parseInt(currentPage) < 1){
currentPage = "1";
}
if(totalPage != 0 && Integer.parseInt(currentPage) > totalPage){
currentPage = totalPage+"";
}
ApplyService applyService = new ApplyServiceImpl();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date date1 = null;
Date date2 = null;
try {
date1 = sdf.parse(start);
date2 = sdf.parse(end);
} catch (ParseException e) {
e.printStackTrace();
}
/*System.out.println("------------------");
System.out.println(date1);
System.out.println(date2);*/
long startDate = date1.getTime();
long endDate = date2.getTime();
int startHour = Integer.parseInt(start.substring(11,13));
int endHour = Integer.parseInt(start.substring(11,13));
if (startDate >= endDate){
out.print("结束时间必须晚于开始时间");
}else if(endDate - startDate >= 1000*60*60*14) {
out.print("预约时常不可超出14小时");
}else if(startHour < 8 || endHour >= 22){
out.print("请在规定的时间段选择预约时间");
}else if (applyService.isExistTime(start,end,mid)){
out.print("此时间段已被预约,请换时间段");
}else {
out.print("ok");
}
}
}
@WebFilter(urlPatterns = "/*",initParams = {@WebInitParam(name = "url",value = "back,login,captcha,reg.jsp,regUser,index,announceList,applyList,meetingList,apply.jsp,meetinglist,autoLogin,top.jsp,css,fonts,images,js")})
public class LoginFilter implements Filter {
private List<String> urls;
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)resp;
request.setCharacterEncoding("utf8");
String requestURI = request.getRequestURI();
/* || requestURI.contains("back") || requestURI.contains("login") || requestURI.contains("reg.jsp") || requestURI.contains("regUser") ||
requestURI.contains("index") || requestURI.contains("announceList") || requestURI.contains("applyList") || requestURI.contains("meetingList") ||
requestURI.contains("apply.jsp") || requestURI.contains("meetinglist") || requestURI.contains("autoLogin") || requestURI.contains("top.jsp")){*/
if(requestURI.equals("/meeting/") || UtilHelper.contains(requestURI,urls)){
chain.doFilter(request, response);
}else {
HttpSession session = request.getSession();
User user = (User)session.getAttribute("user");
if (user != null){
chain.doFilter(request, response);
}else {
response.sendRedirect(request.getContextPath()+"/login.jsp");
}
}
}
public void init(FilterConfig config) throws ServletException {
String url = config.getInitParameter("url");
String[] strs = url.split(",");
urls = Arrays.asList(strs);
}
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf8");
String username = request.getParameter("username");
String password = request.getParameter("password");
String remember = request.getParameter("remember");
String code = request.getParameter("code");
HttpSession session = request.getSession();
String sessionCode = (String)session.getAttribute("code");
if(!(sessionCode != null && sessionCode.equalsIgnoreCase(code))){
request.setAttribute("msg","验证码输入错误,请重新输入");
request.getRequestDispatcher("login.jsp").forward(request,response);
return;
}
UserService userService = new UserServiceImpl();
User user = userService.login(username,password);
if (user != null){
if(remember != null){
//创建了一个2个cookie,分别为(userKey,phone)(ssid,md5Encrypt(phone))
CookieUtils.createCookies(username,request,response,60*60*24*7);
}
session.setAttribute("user",user);
response.sendRedirect("index.jsp");
}else{
request.setAttribute("msg","账号或用户名错误,请重新输入");
request.getRequestDispatcher("login.jsp").forward(request,response);
}
}
}
if(remember != null){
//创建了一个2个cookie,分别为(userKey,phone)(ssid,md5Encrypt(phone))
CookieUtils.createCookies(username,request,response,60*60*24*7);
}
session.setAttribute("user",user);
response.sendRedirect("index.jsp");
}else{
request.setAttribute("msg","账号或用户名错误,请重新输入");
request.getRequestDispatcher("login.jsp").forward(request,response);
}
}
}
@WebServlet("/regForm")
public class RegFormServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
Map<String, String[]> regformMap = request.getParameterMap();
Regform regform = new Regform();
try {
BeanUtils.populate(regform,regformMap);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
public static boolean contains(String str, List<String> lists){
for (String string : lists){
if (str.contains(string)){
return true;
}
}
return false;
}
}
@WebServlet("/addApply")
public class AddApplyServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json;charset=utf-8");
PrintWriter out = response.getWriter();
String start = request.getParameter("start").replace("T"," ");
String end = request.getParameter("end").replace("T"," ");
String mid = request.getParameter("mid");
ApplyService applyService = new ApplyServiceImpl();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date date1 = null;
Date date2 = null;
try {
date1 = sdf.parse(start);
date2 = sdf.parse(end);
} catch (ParseException e) {
e.printStackTrace();
}
/*System.out.println("------------------");
System.out.println(date1);
System.out.println(date2);*/
long startDate = date1.getTime();
long endDate = date2.getTime();
int startHour = Integer.parseInt(start.substring(11,13));
int endHour = Integer.parseInt(start.substring(11,13));
if (startDate >= endDate){
out.print("结束时间必须晚于开始时间");
}else if(endDate - startDate >= 1000*60*60*14) {
out.print("预约时常不可超出14小时");
}else if(startHour < 8 || endHour >= 22){
out.print("请在规定的时间段选择预约时间");
}else if (applyService.isExistTime(start,end,mid)){
out.print("此时间段已被预约,请换时间段");
@WebServlet("/back/changeStatus")
public class ChangeStatusServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf8");
response.setContentType("application/json;charset=utf-8");
PrintWriter out = response.getWriter();
String id = request.getParameter("id");
String status = request.getParameter("status");
String referer = request.getHeader("referer");
MessageService messageService = new MessageServiceImpl();
UserService userService = new UserServiceImpl();
ApplyService applyService = new ApplyServiceImpl();
Message message = new Message();
int count;
if (referer.contains("regformList")){
count = userService.changeStatus(Integer.parseInt(id),Integer.parseInt(status));
if(status.equals("1")){
String username = userService.getNameById(Integer.parseInt(id));
message.setUid(Integer.parseInt(id));
message.setTitle("系统消息");
message.setContent("尊敬的用户"+username+",您好!您的会议室登记信息已通过,现在可以进行会议室预约,祝您使用愉快");
messageService.addMessage(message);
}
}else {
count = applyService.changeStatus(Integer.parseInt(id),Integer.parseInt(status));
if(status.equals("1")){
int uid = applyService.getUid(Integer.parseInt(id));
String username = userService.getNameById(uid);
String meetingName = applyService.getMeetingName(Integer.parseInt(id));
String DateTime = applyService.getDateTime(Integer.parseInt(id));
message.setUid(uid);
message.setTitle("系统消息");
@WebServlet("/back/regformList")
public class RegformListServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String currentPage = request.getParameter("currentPage");
RegformService regformService = new RegformServiceImpl();
int rows = 10;
int totalPage = regformService.getTotalPage(rows);
if(currentPage == null || Integer.parseInt(currentPage) < 1){
currentPage = "1";
}
if(totalPage != 0 && Integer.parseInt(currentPage) > totalPage){
currentPage = totalPage+"";
}
ListPage<RegformList> listPage = regformService.getApplyList(Integer.parseInt(currentPage),rows);
request.setAttribute("listPage",listPage);
request.getRequestDispatcher("regform.jsp").forward(request,response);
}
}
@WebServlet("/back/applyList")
if(password.equals(oldpass)){
int count = userService.updatePassword(id,newpass);
if(count > 0){
request.setAttribute("msg","修改成功");
request.getRequestDispatcher("update.jsp").forward(request,response);
}else {
response.sendRedirect("errorPage.jsp");
}
}else {
request.setAttribute("msg","原密码错误");
request.getRequestDispatcher("update.jsp").forward(request,response);
}
}
}
@WebServlet("/regUser")
public class RegUserServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf8");
Map<String, String[]> userMap = request.getParameterMap();
User user = new User();
try {
BeanUtils.populate(user,userMap);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
UserService userService = new UserServiceImpl();
int status = userService.reqUser(user);
if(status != -1){
@WebFilter(urlPatterns = "/*",initParams = {@WebInitParam(name = "url",value = "back,login,captcha,reg.jsp,regUser,index,announceList,applyList,meetingList,apply.jsp,meetinglist,autoLogin,top.jsp,css,fonts,images,js")})
public class LoginFilter implements Filter {
private List<String> urls;
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)resp;
request.setCharacterEncoding("utf8");
String requestURI = request.getRequestURI();
/* || requestURI.contains("back") || requestURI.contains("login") || requestURI.contains("reg.jsp") || requestURI.contains("regUser") ||
requestURI.contains("index") || requestURI.contains("announceList") || requestURI.contains("applyList") || requestURI.contains("meetingList") ||
requestURI.contains("apply.jsp") || requestURI.contains("meetinglist") || requestURI.contains("autoLogin") || requestURI.contains("top.jsp")){*/
if(requestURI.equals("/meeting/") || UtilHelper.contains(requestURI,urls)){
chain.doFilter(request, response);
}else {
HttpSession session = request.getSession();
User user = (User)session.getAttribute("user");
if (user != null){
chain.doFilter(request, response);
}else {
response.sendRedirect(request.getContextPath()+"/login.jsp");
}
}
}
public void init(FilterConfig config) throws ServletException {
String url = config.getInitParameter("url");
String[] strs = url.split(",");
urls = Arrays.asList(strs);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
Map<String, String[]> applyMap = request.getParameterMap();
Apply apply = new Apply();
try {
ConvertUtils.register(new MyDateConverter(), Date.class);
BeanUtils.populate(apply,applyMap);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
User user = (User)request.getSession().getAttribute("user");
if (user != null){
apply.setUid(user.getId());
ApplyService applyService = new ApplyServiceImpl();
int count = applyService.addApply(apply);
if (count > 0){
request.setAttribute("msg","已发送申请,等待审核通过");
request.getRequestDispatcher("apply.jsp").forward(request,response);
}else {
response.sendRedirect("errorPage.jsp");
}
}else {
response.sendRedirect("login.jsp");
}
}
}
for (String string : lists){
if (str.contains(string)){
return true;
}
}
return false;
}
}
@WebServlet("/addApply")
public class AddApplyServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
Map<String, String[]> applyMap = request.getParameterMap();
Apply apply = new Apply();
try {
ConvertUtils.register(new MyDateConverter(), Date.class);
BeanUtils.populate(apply,applyMap);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
* @param req
* @param resp:调用addCookie方法得response对象
* @param sec:设置Cookie失效日期,单位秒
*/
public static void createCookies(String username, HttpServletRequest req, HttpServletResponse resp, int sec) {
Cookie userCookie = new Cookie("userKey", username);
Cookie ssidCookie = new Cookie("ssid", md5Encrypt(username));
userCookie.setMaxAge(sec);
ssidCookie.setMaxAge(sec);
resp.addCookie(userCookie);
resp.addCookie(ssidCookie);
}
/**
* 这个方法得作用就是加密,把一个明文加载成密文
*
* @param ss
* @return
*/
public static String md5Encrypt(String ss) {
ss = ss == null ? "" : ss + KEY;
char[] md5Digist = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
byte[] ssarr = ss.getBytes();
try {
MessageDigest md = MessageDigest.getInstance("MD5");//md5 sha1 sha2 加密算法
md.update(ssarr);//把明文放到MessageDigest的对象实例去,更新数据
byte[] mssarr = md.digest();
int len = mssarr.length;
char[] str = new char[len*2];
int k = 0;//计数
for(int i=0;i<len;i++) {
byte b = mssarr[i];
str[k++] = md5Digist[b >>> 4 & 0xf];
str[k++] = md5Digist[b & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
UserService userService = new UserServiceImpl();
int status = userService.reqUser(user);
if(status != -1){
response.sendRedirect("login.jsp");
}else{
request.setAttribute("msg","注册失败");
request.getRequestDispatcher("req.jsp").forward(request,response);
}
}
}
@WebServlet("/autoLogin")
public class AutoLoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf8");
Cookie[] cookies = request.getCookies();
String username = null;
String ssid = null;
for (Cookie cookie : cookies){
if(cookie.getName().equals("userKey")){
username = cookie.getValue();
}
if(cookie.getName().equals("ssid")){
ssid = cookie.getValue();
}
}
if(username != null && ssid != null && ssid.equals(CookieUtils.md5Encrypt(username))){
UserService userService = new UserServiceImpl();
User user = userService.getUserForPhone(username);
HttpSession session = request.getSession();
session.setAttribute("user",user);
public class CookieUtils {
private static final String KEY = "cookie@ybzy.com123!";
/**
* 指令浏览器创建cookie文件用的方法
*
* @param username:放到cookie信息里用户名
* @param req
* @param resp:调用addCookie方法得response对象
* @param sec:设置Cookie失效日期,单位秒
*/
public static void createCookies(String username, HttpServletRequest req, HttpServletResponse resp, int sec) {
Cookie userCookie = new Cookie("userKey", username);
Cookie ssidCookie = new Cookie("ssid", md5Encrypt(username));
userCookie.setMaxAge(sec);
ssidCookie.setMaxAge(sec);
resp.addCookie(userCookie);
resp.addCookie(ssidCookie);
}
/**
* 这个方法得作用就是加密,把一个明文加载成密文
*
* @param ss
* @return
*/
public static String md5Encrypt(String ss) {
ss = ss == null ? "" : ss + KEY;
char[] md5Digist = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
byte[] ssarr = ss.getBytes();
try {
MessageDigest md = MessageDigest.getInstance("MD5");//md5 sha1 sha2 加密算法
md.update(ssarr);//把明文放到MessageDigest的对象实例去,更新数据
byte[] mssarr = md.digest();
int len = mssarr.length;
char[] str = new char[len*2];
int k = 0;//计数
for(int i=0;i<len;i++) {
byte b = mssarr[i];
str[k++] = md5Digist[b >>> 4 & 0xf];
str[k++] = md5Digist[b & 0xf];
}
return new String(str);