基于javaweb+mysql的jsp+servlet场馆场地预约管理系统(java+jsp+servlet+mysql+tomcat)

基于javaweb+mysql的jsp+servlet场馆场地预约管理系统(java+jsp+servlet+mysql+tomcat)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

前台可以自由注册,后台只有管理员可以进去。

前台功能:首页、场馆介绍、场馆预约、场馆通知、个人中心。

后台功能:场馆管理、用户管理、预约审核、通知管理、场地管理、场地安排管理。

前台

后台

技术框架

JSP Servlet MySQL Tomcat JavaScript CSS jstl jQuery Bootstrap

基于javaweb+mysql的JSP+Servlet场馆场地预约管理系统(java+jsp+servlet+mysql+tomcat)

        }catch (Exception e){
            e.printStackTrace();
        }
        return "@admin_stadiumPlan_list?pid=" + pid + "&psid=" + psid + "&date=" + request.getParameter("date");
    }

    //列出pid场馆,psid场地,date日的安排列表
    public String list(HttpServletRequest request, HttpServletResponse response, Page page) throws IOException {
        int pid = Integer.parseInt(request.getParameter("pid"));
        Place place = placeDAO.get(pid);
        List<PlaceStadium> placeStadiums = placeStadiumDAO.list(pid);
        //获取场地id号
        int psid = Integer.parseInt(request.getParameter("psid"));
        PlaceStadium placeStadium=new PlaceStadium();
        if(psid!=0){
            placeStadium = placeStadiumDAO.get(psid);
        }else{
         if(placeStadiums.size()>0){
             psid=placeStadiums.get(0).getId();
             placeStadium = placeStadiumDAO.get(psid);
         }
        }
        request.setAttribute("placeStadium", placeStadium);
        //获取请求日期
        String time = request.getParameter("date");
        java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
        if (time != null) {
            date = java.sql.Date.valueOf(time);
        }

        //获取能获取的有效日期
        Date current = new Date(System.currentTimeMillis());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(current);
        List<java.sql.Date> dateValid = new ArrayList<>();
        calendar.add(Calendar.DATE, 0);
        dateValid.add(new java.sql.Date(calendar.getTimeInMillis()));
        calendar.add(Calendar.DATE, 1);
        dateValid.add(new java.sql.Date(calendar.getTimeInMillis()));
        calendar.add(Calendar.DATE, 1);
        dateValid.add(new java.sql.Date(calendar.getTimeInMillis()));

        //获取所有场的安排表

        List<StadiumPlan> stadiumPlanList = stadiumPlanDAO.search(psid, date);
        request.setAttribute("place", place);
        request.setAttribute("placeStadiums", placeStadiums);
        request.setAttribute("stadiumPlanList", stadiumPlanList);

    public String list(HttpServletRequest request, HttpServletResponse response, Page page) {
        List<News> news = newsDAO.list(page.getStart(), page.getCount());
        int total = newsDAO.getTotal();
        page.setTotal(total);

        request.setAttribute("news", news);
        request.setAttribute("page", page);

        return "admin/listNews.jsp";
    }
}

public class BackServletFilter implements Filter {

    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;

        String contextPath=request.getServletContext().getContextPath();
        String uri = request.getRequestURI();
        uri =StringUtils.remove(uri, contextPath);

        if(uri.startsWith("/admin_")){
            String servletPath = StringUtils.substringBetween(uri,"_", "_") + "Servlet";
            String method = StringUtils.substringAfterLast(uri,"_" );
        request.setAttribute("date", date);
        request.setAttribute("where", "book.jsp");

        if (request.getParameter("flag") != null)
            request.setAttribute("flag", 1);

        return "book.jsp";
    }
    //订单生成:安排项修改为:未付款,订单修改为未付款
    public String bookSubmit(HttpServletRequest request, HttpServletResponse response, Page page) {
        /*生成新订单*/
        Reserve reserve = new Reserve();

        /*订单提交的处理*/
        User user =(User) request.getSession().getAttribute("user");    //用户
        int pid = Integer.parseInt(request.getParameter("pid"));     //场馆
        int psid = Integer.parseInt(request.getParameter("psid"));   //场地
        int fare = Integer.parseInt(request.getParameter("fare"));      //总价格

        //新增订单
        reserve.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
        reserve.setName(placeDAO.get(pid).getName()+placeStadiumDAO.get(psid).getName());
        reserve.setFare(fare);
        reserve.setStatus("未付款");
        reserve.setUser(user);

        reserveDAO.add(reserve);

        Enumeration all = request.getParameterNames();

        while(all.hasMoreElements()) {
            String name = all.nextElement().toString();
            if (!name.equals("pid") && !name.equals("psid") && !name.equals("fare")) {
                System.out.println(name);
                //修改安排表项状态
                int itemId = Integer.parseInt(request.getParameter(name));
                stadiumPlanItemDAO.edit(itemId, "未付款"); //编辑状态
                //新增订单项
                ReserveItem reserveItem = new ReserveItem();
                reserveItem.setStadiumPlanItem(stadiumPlanItemDAO.get(itemId));
                reserveItem.setReserveId(reserve.getId());
                reserveItemDAO.add(reserveItem);
            }
        }

        return "@forebook?flag=1";
    }

    //用户页及操作
    public String user(HttpServletRequest request, HttpServletResponse response, Page page) {
        dateValid.add(new java.sql.Date(calendar.getTimeInMillis()));
        calendar.add(Calendar.DATE, 1);
        dateValid.add(new java.sql.Date(calendar.getTimeInMillis()));
        request.setAttribute("dates", dateValid);

        //当前所选场馆、场地、安排表
        String pid = request.getParameter("pid");
        String psid = request.getParameter("psid");

        Place place = null;     //场馆:需要填充场地
        PlaceStadium placeStadium = null;       //场地:需要填充安排表
        String date = null;   //日期:切换场馆或场地设的日期

        //获得场馆
        if (pid == null) {  //未选择场馆
            place = placeList.get(0);
        } else {
            place = placeDAO.get(Integer.parseInt(pid));
        }
        placeStadiumDAO.fill(place);  //填充场馆的场地
        request.setAttribute("place", place);

        //获得场地
        if (psid == null) {   //未选择场地
            placeStadium = place.getPlaceStadium().get(0);
        } else {    //选过场地,移除默认场馆
            placeStadium = placeStadiumDAO.get(Integer.parseInt(psid));
            placeStadiumDAO.fill(placeStadium.getPlace());
            request.removeAttribute("place");
            request.setAttribute("place", placeStadium.getPlace());
        }
        request.setAttribute("placeStadium", placeStadium);
        request.setAttribute("name", placeStadium.getName());

        List<List<StadiumPlan>> lists = new ArrayList<>();
        //每个日期获得一个安排表列表
        for (int i = 0; i < dateValid.size(); i++)
            lists.add(stadiumPlanDAO.search(placeStadium.getId(), dateValid.get(i)));
        request.setAttribute("lists", lists);

        if (date == null) {
            date = dateValid.get(0).toString();
        }

public abstract class BaseBackServlet extends HttpServlet {

    public abstract String add(HttpServletRequest request, HttpServletResponse response, Page page) ;
    public abstract String delete(HttpServletRequest request, HttpServletResponse response, Page page) ;
    public abstract String edit(HttpServletRequest request, HttpServletResponse response, Page page) ;
    public abstract String update(HttpServletRequest request, HttpServletResponse response, Page page) throws UnsupportedEncodingException;
    public abstract String list(HttpServletRequest request, HttpServletResponse response, Page page) throws IOException;

    //用户方面
    protected UserDAO userDAO = new UserDAO();
    //订单方面
    protected ReserveDAO reserveDAO = new ReserveDAO();
    protected ReserveItemDAO reserveItemDAO = new ReserveItemDAO();
    //场地方面
    protected PlaceDAO placeDAO = new PlaceDAO();
    protected PlaceStadiumDAO placeStadiumDAO = new PlaceStadiumDAO();
    protected PlaceImageDAO placeImageDAO = new PlaceImageDAO();
    protected StadiumPlanDAO stadiumPlanDAO = new StadiumPlanDAO();
    protected StadiumPlanItemDAO stadiumPlanItemDAO = new StadiumPlanItemDAO();
    //通知方面
    protected NewsDAO newsDAO = new NewsDAO();

    public void service(HttpServletRequest request, HttpServletResponse response) {
        try {
            /*获取分页信息*/
            int start= 0;
            int count = 5;
            try {
                start = Integer.parseInt(request.getParameter("page.start"));
            } catch (Exception e) {

            }
            try {
                count = Integer.parseInt(request.getParameter("page.count"));
            } catch (Exception e) {
            }
            Page page = new Page(start,count);

            /*借助反射,调用对应的方法*/
            String method = (String) request.getAttribute("method");

    //无add操作
    public String add(HttpServletRequest request, HttpServletResponse response, Page page) {
        return "#";
    }
    //需要修改
    public String delete(HttpServletRequest request, HttpServletResponse response, Page page) {
        return null;
    }

    public String edit(HttpServletRequest request, HttpServletResponse response, Page page) {
        return null;
    }

    public String update(HttpServletRequest request, HttpServletResponse response, Page page) {
        return null;
    }

    public String list(HttpServletRequest request, HttpServletResponse response, Page page) {

        List<Reserve> reserveList = reserveDAO.list(page.getStart(), page.getCount());
        int total = reserveDAO.getTotal();
        page.setTotal(total);
        for (int i = 0; i < reserveList.size(); i++) {
            reserveItemDAO.fill(reserveList.get(i));
        }
        request.setAttribute("reserveList", reserveList);
        request.setAttribute("page", page);
        return "admin/listReserve.jsp";
    }

    /*提交后:安排项修改为:未付款,订单修改为未付款*/
    //审核通过:安排表项修改为:,订单修改为占用
    public String pass(HttpServletRequest request, HttpServletResponse response, Page page) {
        int rid = Integer.parseInt(request.getParameter("rid"));
        reserveDAO.edit(rid, "审核通过");
        Reserve reserve = new Reserve();
        reserve.setId(rid);
        reserveItemDAO.fill(reserve);
        for (int i = 0; i < reserve.getReserveItemList().size(); i++) {
            stadiumPlanItemDAO.edit(reserve.getReserveItemList().get(i).getStadiumPlanItem().getId(), "已预约");
        }
        PlaceStadium placeStadium = null;       //场地:需要填充安排表
        String date = null;   //日期:切换场馆或场地设的日期

        //获得场馆
        if (pid == null) {  //未选择场馆
            place = placeList.get(0);
        } else {
            place = placeDAO.get(Integer.parseInt(pid));
        }
        placeStadiumDAO.fill(place);  //填充场馆的场地
        request.setAttribute("place", place);

        //获得场地
        if (psid == null) {   //未选择场地
            placeStadium = place.getPlaceStadium().get(0);
        } else {    //选过场地,移除默认场馆
            placeStadium = placeStadiumDAO.get(Integer.parseInt(psid));
            placeStadiumDAO.fill(placeStadium.getPlace());
            request.removeAttribute("place");
            request.setAttribute("place", placeStadium.getPlace());
        }
        request.setAttribute("placeStadium", placeStadium);
        request.setAttribute("name", placeStadium.getName());

        List<List<StadiumPlan>> lists = new ArrayList<>();
        //每个日期获得一个安排表列表
        for (int i = 0; i < dateValid.size(); i++)
            lists.add(stadiumPlanDAO.search(placeStadium.getId(), dateValid.get(i)));
        request.setAttribute("lists", lists);

        if (date == null) {
            date = dateValid.get(0).toString();
        }
        request.setAttribute("date", date);
        request.setAttribute("where", "book.jsp");

        if (request.getParameter("flag") != null)
            request.setAttribute("flag", 1);

        return "book.jsp";
    }
    //订单生成:安排项修改为:未付款,订单修改为未付款
    public String bookSubmit(HttpServletRequest request, HttpServletResponse response, Page page) {
        /*生成新订单*/
        Reserve reserve = new Reserve();

        /*订单提交的处理*/
        User user =(User) request.getSession().getAttribute("user");    //用户
        File file = new File(imageFolder, place.getId() + ".jpg");

        try {
            if (is != null && is.available() != 0) {
                try(FileOutputStream fos = new FileOutputStream(file)) {
                    byte b[] = new byte[1024 * 1024];
                    int length = 0;
                    while ((length = is.read(b)) != -1) {
                        fos.write(b, 0, length);
                    }
                    fos.flush();
                    BufferedImage img = ImageUtil.change2jpg(file);
                    ImageIO.write(img, "jpg", file);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "@admin_place_list";
    }

    public String delete(HttpServletRequest request, HttpServletResponse response, Page page) {
        int id = Integer.parseInt(request.getParameter("id"));
        placeDAO.delete(id);
        return "@admin_place_list";
    }

    public String edit(HttpServletRequest request, HttpServletResponse response, Page page) {
        return "";
    }

    public String update(HttpServletRequest request, HttpServletResponse response, Page page) throws UnsupportedEncodingException {
        Map<String, String> params = new HashMap<>();
        InputStream is = super.parseUpload(request, params);

        Place place = new Place();
        String name = params.get("name");
        String ename = params.get("ename");
        String location = params.get("location");
        String introduction = params.get("introduction");
        place.setId(Integer.parseInt(params.get("id")));
            reserveItemDAO.fill(reserveList.get(i));
        }
        request.setAttribute("reserveList", reserveList);
        return "user.jsp";
    }

    public String useredit(HttpServletRequest request, HttpServletResponse response, Page page) {
        User user = (User)request.getSession().getAttribute("user");
        user.setEmail(request.getParameter("email"));
        userDAO.update(user);
        return user(request, response, page);
    }
    //付款及修改状态
    public String userPay(HttpServletRequest request, HttpServletResponse response, Page page) {
        int rid = Integer.parseInt(request.getParameter("rid"));
        Reserve reserve = new Reserve();
        reserve.setId(rid);
        //订单状态修改为已支付
        reserveDAO.edit(rid, "审核中");
        //场地安排表项状态修改为"审核中"
        reserveItemDAO.fill(reserve);
        for (int i = 0; i < reserve.getReserveItemList().size(); i++) {
            stadiumPlanItemDAO.edit(reserve.getReserveItemList().get(i).getId(), "审核中");
        }
        return "@foreuser";
    }

    public String deleteReserve(HttpServletRequest request, HttpServletResponse response, Page page) {
        reserveDAO.delete(Integer.parseInt(request.getParameter("rid")));
        return "@foreuser";
    }

    //通知页
    public String news(HttpServletRequest request, HttpServletResponse response, Page page) {
        request.setAttribute("where", "news.jsp");

        List<News> newsList = newsDAO.list();
        request.setAttribute("newsList", newsList);
        return "news.jsp";
    }

    public String newsShow(HttpServletRequest request, HttpServletResponse response, Page page) {
        request.setAttribute("where", "news.jsp");

        int id = Integer.parseInt(request.getParameter("nid"));
        News news = newsDAO.get(id);
        request.setAttribute("news", news);
        return "newsShow.jsp";
    }
        try {
            if (is != null && is.available() != 0) {
                try(FileOutputStream fos = new FileOutputStream(file)) {
                    byte b[] = new byte[1024 * 1024];
                    int length = 0;
                    while ((length = is.read(b)) != -1) {
                        fos.write(b, 0, length);
                    }
                    fos.flush();
                    BufferedImage img = ImageUtil.change2jpg(file);
                    ImageIO.write(img, "jpg", file);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "@admin_place_list";
    }

    public String delete(HttpServletRequest request, HttpServletResponse response, Page page) {
        int id = Integer.parseInt(request.getParameter("id"));
        placeDAO.delete(id);
        return "@admin_place_list";
    }

    public String edit(HttpServletRequest request, HttpServletResponse response, Page page) {
        return "";
    }

    public String update(HttpServletRequest request, HttpServletResponse response, Page page) throws UnsupportedEncodingException {
        Map<String, String> params = new HashMap<>();
        InputStream is = super.parseUpload(request, params);

        Place place = new Place();
        String name = params.get("name");
        String ename = params.get("ename");
        String location = params.get("location");
        String introduction = params.get("introduction");
        place.setId(Integer.parseInt(params.get("id")));
        place.setName(name);
        place.setEname(ename);
        place.setLocation(location);
        place.setIntroduction(introduction);
        placeDAO.update(place);
            File imageFolder = new File(request.getSession().getServletContext().getRealPath("image/place"));
        if(!imageFolder.exists()){
            imageFolder.mkdirs();

@WebServlet(name = "NewsServlet")
public class NewsServlet extends BaseBackServlet {
    public String add(HttpServletRequest request, HttpServletResponse response, Page page) {

        Map<String, String> params = new HashMap<>();
        InputStream is = super.parseUpload(request, params);

        News news = new News();
        news.setTitle(params.get("title"));
        news.setContent(params.get("content"));
        news.setTime(new Date(System.currentTimeMillis()));

        newsDAO.add(news);
        return "@admin_news_list";
    }

    public String delete(HttpServletRequest request, HttpServletResponse response, Page page) {
        int nid = Integer.parseInt(request.getParameter("nid"));
        newsDAO.delete(nid);
        return "@admin_news_list";
    }

    public String edit(HttpServletRequest request, HttpServletResponse response, Page page) {
        int id = Integer.parseInt(request.getParameter("id"));
        News news = newsDAO.get(id);
        request.setAttribute("news", news);
        return "admin/editNews.jsp";
    }

    public String update(HttpServletRequest request, HttpServletResponse response, Page page) throws UnsupportedEncodingException {
        News news = newsDAO.get(Integer.parseInt(request.getParameter("id")));
    }

    public String update(HttpServletRequest request, HttpServletResponse response, Page page) {
        int pid = Integer.parseInt(request.getParameter("pid"));
        int psid = Integer.parseInt(request.getParameter("psid"));
        int itemId = Integer.parseInt(request.getParameter("itemId"));
        try{
            stadiumPlanItemDAO.edit(itemId,"已预约");
        }catch (Exception e){
            e.printStackTrace();
        }
        return "@admin_stadiumPlan_list?pid=" + pid + "&psid=" + psid + "&date=" + request.getParameter("date");
    }

    //列出pid场馆,psid场地,date日的安排列表
    public String list(HttpServletRequest request, HttpServletResponse response, Page page) throws IOException {
        int pid = Integer.parseInt(request.getParameter("pid"));
        Place place = placeDAO.get(pid);
        List<PlaceStadium> placeStadiums = placeStadiumDAO.list(pid);
        //获取场地id号
        int psid = Integer.parseInt(request.getParameter("psid"));
        PlaceStadium placeStadium=new PlaceStadium();
        if(psid!=0){
            placeStadium = placeStadiumDAO.get(psid);
        }else{
         if(placeStadiums.size()>0){
             psid=placeStadiums.get(0).getId();
             placeStadium = placeStadiumDAO.get(psid);
         }
        }
        request.setAttribute("placeStadium", placeStadium);
        //获取请求日期
        String time = request.getParameter("date");
        java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
        if (time != null) {
            date = java.sql.Date.valueOf(time);
        }

        //获取能获取的有效日期
        Date current = new Date(System.currentTimeMillis());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(current);
        List<java.sql.Date> dateValid = new ArrayList<>();
        calendar.add(Calendar.DATE, 0);
        dateValid.add(new java.sql.Date(calendar.getTimeInMillis()));
        calendar.add(Calendar.DATE, 1);
        dateValid.add(new java.sql.Date(calendar.getTimeInMillis()));
        calendar.add(Calendar.DATE, 1);
        dateValid.add(new java.sql.Date(calendar.getTimeInMillis()));
        request.setAttribute("news", newsList);
        request.setAttribute("where", "home.jsp");
        return "home.jsp";
    }
    //场馆介绍页
    public String introduce(HttpServletRequest request, HttpServletResponse response, Page page) {
        request.setAttribute("where", "introduce.jsp");

        List<Place> placeList = placeDAO.list();
        request.setAttribute("placeList", placeList);

        return "introduce.jsp";
    }

    //注册
    public String register(HttpServletRequest request, HttpServletResponse response, Page page) {
        try {
            String name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
            String password = request.getParameter("password");
            String email = request.getParameter("email");
            name = HtmlUtils.htmlEscape(name);
            boolean exist = userDAO.isExist(name);

            if (exist) {
                request.setAttribute("msg", "*用户名已经被使用!");
                return "register.jsp";
            }
            User user = new User();
            user.setName(name);
            user.setPassword(password);
            user.setEmail(email);
            userDAO.add(user);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return login(request, response, page);
    }

    //登陆、登出
    public String login(HttpServletRequest request, HttpServletResponse response, Page page) {
        try {
            String name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
            name = HtmlUtils.htmlEscape(name);
            String password = request.getParameter("password");

            user.setEmail(email);
            userDAO.add(user);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return login(request, response, page);
    }

    //登陆、登出
    public String login(HttpServletRequest request, HttpServletResponse response, Page page) {
        try {
            String name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
            name = HtmlUtils.htmlEscape(name);
            String password = request.getParameter("password");

            User user = userDAO.get(name, password);

            if (user == null) {
                request.setAttribute("msg", "账号密码错误");
                return "login.jsp";
            } else if (user.getName().equals("admin")) {
                return "@admin_place_list";
            }
            request.getSession().setAttribute("user", user);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return "@forehome";
    }

    public String logout(HttpServletRequest request, HttpServletResponse response, Page page) {
        request.getSession().removeAttribute("user");
        return "@forehome";
    }

    public String checkLogin(HttpServletRequest request, HttpServletResponse response, Page page) {
        User user =(User) request.getSession().getAttribute("user");
        if(null!=user)
            return "%success";
        return "%fail";
    }

    public String loginAjax(HttpServletRequest request, HttpServletResponse response, Page page) {
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        User user = userDAO.get(name,password);

        if(null==user){
        request.setAttribute("date", date);
        request.setAttribute("where", "book.jsp");

        if (request.getParameter("flag") != null)
            request.setAttribute("flag", 1);

        return "book.jsp";
    }
    //订单生成:安排项修改为:未付款,订单修改为未付款
    public String bookSubmit(HttpServletRequest request, HttpServletResponse response, Page page) {
        /*生成新订单*/
        Reserve reserve = new Reserve();

        /*订单提交的处理*/
        User user =(User) request.getSession().getAttribute("user");    //用户
        int pid = Integer.parseInt(request.getParameter("pid"));     //场馆
        int psid = Integer.parseInt(request.getParameter("psid"));   //场地
        int fare = Integer.parseInt(request.getParameter("fare"));      //总价格

        //新增订单
        reserve.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
        reserve.setName(placeDAO.get(pid).getName()+placeStadiumDAO.get(psid).getName());
        reserve.setFare(fare);
        reserve.setStatus("未付款");
        reserve.setUser(user);

        reserveDAO.add(reserve);

        Enumeration all = request.getParameterNames();

        while(all.hasMoreElements()) {
            String name = all.nextElement().toString();
            if (!name.equals("pid") && !name.equals("psid") && !name.equals("fare")) {
                System.out.println(name);
                //修改安排表项状态
                int itemId = Integer.parseInt(request.getParameter(name));
                stadiumPlanItemDAO.edit(itemId, "未付款"); //编辑状态
                //新增订单项
                ReserveItem reserveItem = new ReserveItem();
                reserveItem.setStadiumPlanItem(stadiumPlanItemDAO.get(itemId));
                reserveItem.setReserveId(reserve.getId());
                reserveItemDAO.add(reserveItem);
            }
    public String add(HttpServletRequest request, HttpServletResponse response, Page page) {
        Map<String, String> params = new HashMap<>();
        InputStream is = super.parseUpload(request, params);

        Place place = new Place();

        place.setName(params.get("name"));
        place.setEname(params.get("ename"));
        place.setLocation(params.get("location"));
        place.setIntroduction(params.get("introduction"));
        placeDAO.add(place);

        File imageFolder = new File(request.getSession().getServletContext().getRealPath("image/place"));
        if(!imageFolder.exists()){
            imageFolder.mkdirs();
        }
        //System.out.println(request.getSession().getServletContext().getRealPath("image/place"));
        File file = new File(imageFolder, place.getId() + ".jpg");

        try {
            if (is != null && is.available() != 0) {
                try(FileOutputStream fos = new FileOutputStream(file)) {
                    byte b[] = new byte[1024 * 1024];
                    int length = 0;
                    while ((length = is.read(b)) != -1) {
                        fos.write(b, 0, length);
                    }
                    fos.flush();
                    BufferedImage img = ImageUtil.change2jpg(file);
                    ImageIO.write(img, "jpg", file);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "@admin_place_list";
    }

    public String delete(HttpServletRequest request, HttpServletResponse response, Page page) {
        int id = Integer.parseInt(request.getParameter("id"));
        placeDAO.delete(id);
        return "@admin_place_list";
    }

    public String edit(HttpServletRequest request, HttpServletResponse response, Page page) {
        return "";
    }

    public String update(HttpServletRequest request, HttpServletResponse response, Page page) throws UnsupportedEncodingException {
                        ImageIO.write(img, "jpg", file);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        return "@admin_place_list";
    }

    public String list(HttpServletRequest request, HttpServletResponse response, Page page) {
        List<Place> places = placeDAO.list(page.getStart(), page.getCount());
        int total = placeDAO.getTotal();
        page.setTotal(total);

        request.setAttribute("places", places);
        request.setAttribute("page", page);

        return "admin/listPlace.jsp";
    }

}

public class StadiumPlanServlet extends BaseBackServlet{
    public String add(HttpServletRequest request, HttpServletResponse response, Page page) {
        return null;
    }
    public String delete(HttpServletRequest request, HttpServletResponse response, Page page) {
        return null;
    }
    public String edit(HttpServletRequest request, HttpServletResponse response, Page page) {

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值