渣渣兔 发表于 2024-8-26 10:51:14

基于javaweb+mysql的jsp+servlet聚会会议室预约体系(java+jsp+bootstrap+servle

基于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 登录

public class UtilHelper {

        /**
       * 获取当前日期时间
       */
        public static String getTime() {
                Date date = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                return sdf.format(date);

        }

        /**
       * 把date对象转换成String
       * @param date
       */
        public static String dateToString(Date date) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                return sdf.format(date);
        }

        /**
       *
       * @param num
       * @return
       */
        public static DateTime createDateTime(int num, HttpServletRequest request){
                LocalDate ld = LocalDate.now();
                int week = ld.getDayOfWeek().getValue();

                LocalDate date = ld.plusWeeks(num);

                LocalDate monday = date.plusDays(-(week-1));
                LocalDate tuesday = monday.plusDays(1);
                LocalDate wednesday = tuesday.plusDays(1);
                LocalDate thursday = wednesday.plusDays(1);
                LocalDate friday = thursday.plusDays(1);
                LocalDate saturday = friday.plusDays(1);
                LocalDate sunday = saturday.plusDays(1);

                DateTime dateTime = new DateTime();

@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("系统消息");
                message.setContent("尊敬的用户"+username+",您好!您预约于"+DateTime+meetingName+"号会议室已经预约通过,请您注意时间,准时到达.");
                messageService.addMessage(message);
            }
      }
      if (count > 0){
      AjaxBean ajaxBean = new AjaxBean();
      ajaxBean.setDateTime(datetime);
      ajaxBean.setMap(pageBeanMap);

      /*System.out.println(ajaxBean);*/

      Gson gson = new Gson();
      String json = gson.toJson(ajaxBean);

      out.print(json);

    }
}

@WebServlet("/login")
public class LoginServlet 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");
      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);

@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);
                request.getRequestDispatcher("apply.jsp").forward(request,response);
            }else {
                response.sendRedirect("errorPage.jsp");
            }
      }else {
            response.sendRedirect("login.jsp");
      }
    }
}

@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") ||

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

      User user = (User)request.getSession().getAttribute("user");
      if (user != null){
            apply.setUid(user.getId());
            ApplyService applyService = new ApplyServiceImpl();
            int count = applyService.addApply(apply);

@WebServlet("/back/modifyMeeting")
public class ModifyMeetingServlet 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[]> meetingMap = request.getParameterMap();
      Meeting meeting = new Meeting();

      try {
            BeanUtils.populate(meeting,meetingMap);
      } catch (IllegalAccessException e) {
            e.printStackTrace();
      } catch (InvocationTargetException e) {
            e.printStackTrace();
      }

      MeetingService meetingService = new MeetingServiceImpl();
      int count = meetingService.updateMeeting(meeting);

      if (count > 0){
            response.sendRedirect("meetingList");
      }else {
            response.sendRedirect("../errorPage.jsp");
      }

    }
}

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

public class UtilHelper {

        /**
       * 获取当前日期时间
       */
        public static String getTime() {
                Date date = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                return sdf.format(date);

        }

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

@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);

    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("此时间段已被预约,请换时间段");
      }else {
            out.print("ok");
      }
    }
}

@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")
public class ApplyListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       * @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");//md5sha1sha2加密算法
                        md.update(ssarr);//把明文放到MessageDigest的对象实例去,更新数据
                        byte[] mssarr = md.digest();
                       
                        int len = mssarr.length;
                        char[] str = new char;
                        int k = 0;//计数
                       
                        for(int i=0;i<len;i++) {
                                byte b = mssarr;
                                str = md5Digist;
                                str = md5Digist;
                        }
                        return new String(str);
                } catch (Exception e) {
                        e.printStackTrace();
                }
                return null;
        }

}

@WebServlet("/back/modifyMeeting")
public class ModifyMeetingServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      this.doGet(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){
            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 {
      }else {
            HttpSession session = request.getSession();
            Admin admin = (Admin) session.getAttribute("admin");
            if (admin != null){
                chain.doFilter(request,response);
            }else {
                response.sendRedirect("login.jsp");
            }
      }
    }

    public void init(FilterConfig config) throws ServletException {
      String url = config.getInitParameter("url");
      String[] split = url.split(",");
      urls = Arrays.asList(split);
    }

}

@WebServlet("/modifyPassword")
public class ModifyPasswordServlet 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");
      String id = request.getParameter("id");
      String oldpass = request.getParameter("oldpass");
      String newpass = request.getParameter("newpass");

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

public class UtilHelper {

        /**
       * 获取当前日期时间
       */
        public static String getTime() {
                Date date = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                return sdf.format(date);

        }

        /**       * 把date对象转换成String       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");
      }
    }
}

public class UtilHelper {

        /**
       * 获取当前日期时间
       */
        public static String getTime() {
https://i-blog.csdnimg.cn/blog_migrate/31fbf95035e88301d9b1998142707fa0.jpeg
https://i-blog.csdnimg.cn/blog_migrate/2626111365f88713af800d136c870645.jpeg
https://i-blog.csdnimg.cn/blog_migrate/9ec7fbd4287ef94498ed08e0e9ab39ea.jpeg
https://i-blog.csdnimg.cn/blog_migrate/ea97b1207f4ebe6b77fe6c2a878119a6.jpeg
https://i-blog.csdnimg.cn/blog_migrate/fe7c3ccd704d638b766c55e1c98d4591.jpeg
https://i-blog.csdnimg.cn/blog_migrate/cb7f34de03f29ab14f4255bef253e3ef.jpeg
https://i-blog.csdnimg.cn/blog_migrate/04df3f721dba478a601a45b0f54b44ff.jpeg
https://i-blog.csdnimg.cn/blog_migrate/b452899cb1bac0b789603c8b5cc32760.jpeghttps://i-blog.csdnimg.cn/blog_migrate/584792af70f2872162c65874c2da1ace.jpeghttps://i-blog.csdnimg.cn/blog_migrate/82a374f64558c390a54c9f40348dfa62.jpeg

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 基于javaweb+mysql的jsp+servlet聚会会议室预约体系(java+jsp+bootstrap+servle