基于javaweb+jsp的酒店管理系统

基于javaweb+jsp的酒店管理系统

JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap.

基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可

开发工具:eclipse/idea/myeclipse/sts等均可配置运行

适用

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

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //过滤编码
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String action = Util.decode(request, "action");
        if ("add".equals(action)) {//增加
            Good vo = new Good();
            //取出页面传进来的各个数据,并设置到Good对象的属性里
            vo.setGoodName(Util.decode(request, "goodName"));
            vo.setGoodType(Util.decode(request, "goodType"));
            vo.setGoodCount(Util.decode(request, "goodCount"));
            vo.setGoodUnit(Util.decode(request, "goodUnit"));
            vo.setGoodPrice(Util.decode(request, "goodPrice"));
            vo.setGoodText(Util.decode(request, "goodText"));
            GoodService goodService = new GoodServiceImpl();
            //调用Service层增加方法(add),增加记录
            goodService.add(vo);
            this.redirectList(request, response);
        } else if ("delete".equals(action)) {//删除
            //取出表要删除的商品记录的主键
                    vo.setLodgingEnd(rs.getString("lodging_end"));
                    vo.setLodgingPrice(rs.getString("lodging_price"));
                    vo.setLodgingText(rs.getString("lodging_text"));
                    list.add(vo);
                }
            String sqlCount = "select count(*) from `t_lodging` where 1=1 " + condition;
            ps = c.prepareStatement(sqlCount);
            rs = ps.executeQuery();
            if (rs.next()) {
                totalCount = rs.getInt(1);
            }
            rs.close();
            ps.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, Object> result = new HashMap();
        result.put("list", list);
        result.put("totalCount", totalCount);
                <td width="12%">姓名:td><td><input class="index-content-table-td-add" type="text" id="realName" name="realName" value="${vo.realName}"/>td>
            tr>
            <tr>
                <td width="12%">性别:td>
                <td>
                          
                          
                td>
            tr>
            <tr>
                <td width="12%">手机:td><td><input class="index-content-table-td-add" type="text" id="userPhone" name="userPhone" value="${vo.userPhone}"/>td>
            tr>
            <tr>
                <td width="12%">备注:td><td><textarea id="userText" name="userText" style="width: 60%; height: 100px;padding: 0px 17px;" placeholder="请输入内容......">${vo.userText}textarea>td>
            tr>
        request.getSession().setAttribute("list", map.get("list"));

        Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
        String pageNum = Util.decode(request, "pageNum");//封装分页参数
        com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
        params.put("startIndex", pb.getStartIndex());
        params.put("pageSize", pb.getPageSize());
        List list = (List) roomService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
        pb.setServlet("RoomServlet");
        pb.setSearchColumn(searchColumn);
        pb.setKeyword(keyword);
        pb.setList(list);
        request.getSession().setAttribute("pageBean", pb);
        request.getSession().setAttribute("list", pb.getList());

        response.sendRedirect("room_list.jsp");
    }
}
package com.demo.servlet;
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //过滤编码
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String action = Util.decode(request, "action");
        if ("login".equalsIgnoreCase(action)) {//登录
            String username = Util.decode(request, "username");
            String password = Util.decode(request, "password");

            String validationCode = Util.decode(request, "validationCode");
            if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过
                request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");
                request.getRequestDispatcher("login.jsp").forward(request, response);
                return;
            }

            UserService userService = new UserServiceImpl();
            Map<String, Object> params = new HashMap();
            params.put("searchColumn", "username");//使用`username`字段进行模糊查询
            ps.execute();
            ps.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //@Override
    public void update(Room vo) {
        String sql = "update `t_room` set `room_name` = ? ,`room_level` = ? ,`room_status` = ? ,`room_bedcount` = ? ,`room_hourprice` = ? ,`room_dayprice` = ? ,`room_text` = ?  where `id` = ?";
        try {
            Connection c = Util.getConnection();
            PreparedStatement ps = c.prepareStatement(sql);
            
            ps.setString(1, vo.getRoomName());
            ps.setString(2, vo.getRoomLevel());
            ps.setString(3, vo.getRoomStatus());
            ps.setString(4, vo.getRoomBedcount());
            ps.setString(5, vo.getRoomHourprice());
            ps.setString(6, vo.getRoomDayprice());
            params.put("keyword", username);
            params.put("startIndex", 0);
            params.put("pageSize", Long.MAX_VALUE);
            List<User> list = (List<User>) userService.list(params).get("list");
            for (User user : list) {
                if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册
                    request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");
                    request.getRequestDispatcher("register.jsp").forward(request, response);
                    return;
                }
            }
            User vo = new User();
            vo.setUsername(username);
            vo.setPassword(password);
            //vo.setUserType("普通用户");//需要设置一个默认值
            userService.add(vo);
            Map<String, Object> params = new HashMap();
            params.put("searchColumn", "username");//使用`username`字段进行模糊查询
            params.put("keyword", username);
            params.put("startIndex", 0);
            params.put("pageSize", Long.MAX_VALUE);
            List<User> list = (List<User>) userService.list(params).get("list");
            for (User user : list) {
                if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册
                    request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");
                    request.getRequestDispatcher("register.jsp").forward(request, response);
                    return;
                }
            }
            User vo = new User();
            vo.setUsername(username);
            vo.setPassword(password);
            //vo.setUserType("普通用户");//需要设置一个默认值
            userService.add(vo);
            request.getSession().setAttribute("alert_msg", "注册成功!用户名:[" + username + "]");
            request.getRequestDispatcher("login.jsp").forward(request, response);
        } else if ("logout".equalsIgnoreCase(action)) {//登出
            HttpSession session = request.getSession();
            User user = (User) session.getAttribute("loginUser");
    function check() {
        //根据ID获取值
        if (document.getElementById("lodgingName").value.trim().length == 0) {
            alert("姓名不能为空!");
            return false;
        }
        if (document.getElementById("lodgingId").value.trim().length == 0) {
            alert("证件号不能为空!");
            return false;
        }
        if (document.getElementById("lodgingPhone").value.trim().length == 0) {
            alert("电话不能为空!");
            return false;
        }
        if (document.getElementById("lodgingRoomno").value.trim().length == 0) {
            alert("房间号不能为空!");
            return false;
        }
        if (document.getElementById("lodgingStart").value.trim().length == 0) {
            alert("开始时间不能为空!");
            return false;
        }
        if (document.getElementById("lodgingEnd").value.trim().length == 0) {
            alert("结束时间不能为空!");
            <tr>
                <td width="12%">备注:td><td><textarea id="roomText" name="roomText" style="width: 60%; height: 100px;padding: 0px 17px;" placeholder="请输入内容......">${vo.roomText}textarea>td>
            tr>
        table>
        <br>
        <br>
        <br>
           <button type="submit" class="btn btn-grad btn-primary btn-sm">提交button>        <button type="button" class="btn btn-grad btn-primary btn-sm" onclick="javascript:history.back(-1);">取消button>
    form>
div>

body>
<script type="text/javascript">
    //提交之前进行检查,如果return false,则不允许提交
    function check() {
        //根据ID获取值
        if (document.getElementById("roomName").value.trim().length == 0) {
            alert("房间号不能为空!");
            return false;
        }
        if (document.getElementById("roomBedcount").value.trim().length == 0) {
            String validationCode = Util.decode(request, "validationCode");
            if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过
                request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");
                request.getRequestDispatcher("login.jsp").forward(request, response);
                return;
            }

            UserService userService = new UserServiceImpl();
            Map<String, Object> params = new HashMap();
            params.put("searchColumn", "username");//使用`username`字段进行模糊查询
            params.put("keyword", username);
            List<User> list = (List<User>) userService.list(params).get("list");
            for (User user : list) {
                if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了
                    request.getSession().setAttribute("loginUser", user);
                    request.getRequestDispatcher("UserServlet").forward(request, response);
                    return;
                }
            vo.setUserPhone(Util.decode(request, "userPhone"));
            vo.setUserText(Util.decode(request, "userText"));
            vo.setUserType(Util.decode(request, "userType"));
            UserService userService = new UserServiceImpl();
            //调用Service层增加方法(add),增加记录
            userService.add(vo);
            this.redirectList(request, response);
        } else if ("delete".equals(action)) {//删除
            //取出表要删除的用户记录的主键
            long id = Long.parseLong(Util.decode(request, "id"));
            UserService userService = new UserServiceImpl();
            //调用Service层删除方法(delete),将对应的记录删除
            userService.delete(id);
            this.redirectList(request, response);
        } else if ("edit".equals(action)) {//修改
            //取出页面传进来的各个数据,并设置到User对象的属性里
            User vo = new User();
            goodService.add(vo);
            this.redirectList(request, response);
        } else if ("delete".equals(action)) {//删除
            //取出表要删除的商品记录的主键
            long id = Long.parseLong(Util.decode(request, "id"));
            GoodService goodService = new GoodServiceImpl();
            //调用Service层删除方法(delete),将对应的记录删除
            goodService.delete(id);
            this.redirectList(request, response);
        } else if ("edit".equals(action)) {//修改
            //取出页面传进来的各个数据,并设置到Good对象的属性里
            Good vo = new Good();
            vo.setId(Long.valueOf(Util.decode(request, "id")));
            vo.setGoodName(Util.decode(request, "goodName"));
            vo.setGoodType(Util.decode(request, "goodType"));
            vo.setGoodCount(Util.decode(request, "goodCount"));
            this.redirectList(request, response);
        } else if ("delete".equals(action)) {//删除
            //取出表要删除的商品记录的主键
            long id = Long.parseLong(Util.decode(request, "id"));
            GoodService goodService = new GoodServiceImpl();
            //调用Service层删除方法(delete),将对应的记录删除
            goodService.delete(id);
            this.redirectList(request, response);
        } else if ("edit".equals(action)) {//修改
            //取出页面传进来的各个数据,并设置到Good对象的属性里
            Good vo = new Good();
            vo.setId(Long.valueOf(Util.decode(request, "id")));
            vo.setGoodName(Util.decode(request, "goodName"));
            vo.setGoodType(Util.decode(request, "goodType"));
            vo.setGoodCount(Util.decode(request, "goodCount"));
            vo.setGoodUnit(Util.decode(request, "goodUnit"));
            vo.setGoodPrice(Util.decode(request, "goodPrice"));
            //调用Service层删除方法(delete),将对应的记录删除
            roomService.delete(id);
            this.redirectList(request, response);
        } else if ("edit".equals(action)) {//修改
            //取出页面传进来的各个数据,并设置到Room对象的属性里
            Room vo = new Room();
            vo.setId(Long.valueOf(Util.decode(request, "id")));
            vo.setRoomName(Util.decode(request, "roomName"));
            vo.setRoomLevel(Util.decode(request, "roomLevel"));
            vo.setRoomStatus(Util.decode(request, "roomStatus"));
            vo.setRoomBedcount(Util.decode(request, "roomBedcount"));
            vo.setRoomHourprice(Util.decode(request, "roomHourprice"));
            vo.setRoomDayprice(Util.decode(request, "roomDayprice"));
            vo.setRoomText(Util.decode(request, "roomText"));
            RoomService roomService = new RoomServiceImpl();
            //调用Service层更新方法(update),更新记录
            roomService.update(vo);
            this.redirectList(request, response);
                rs = ps.executeQuery();
                while (rs.next()) {
                    Room vo = new Room();
                    vo.setId(rs.getLong("id"));
                    vo.setRoomName(rs.getString("room_name"));
                    vo.setRoomLevel(rs.getString("room_level"));
                    vo.setRoomStatus(rs.getString("room_status"));
                    vo.setRoomBedcount(rs.getString("room_bedcount"));
                    vo.setRoomHourprice(rs.getString("room_hourprice"));
                    vo.setRoomDayprice(rs.getString("room_dayprice"));
                    vo.setRoomText(rs.getString("room_text"));
        }
        Map<String, Object> result = new HashMap();
        result.put("list", list);
        result.put("totalCount", totalCount);
        return result;
    }
}
package com.demo.servlet;

import com.demo.util.Util;
import com.demo.service.RoomService;
    function check() {
        //根据ID获取值
        if (document.getElementById("username").value.trim().length == 0) {
            alert("用户名不能为空!");
            return false;
        }
        if (document.getElementById("password").value.trim().length == 0) {
            alert("密码不能为空!");
            return false;
        }
        if (document.getElementById("realName").value.trim().length == 0) {
            alert("姓名不能为空!");
            return false;
        }
    <div class="index-content-operation">
        <a class="info-detail">修改客房a>
        <br>
        <br>
    div>
    <br>
    <form action="RoomServlet?action=edit" method="post" onsubmit="return check()">
        <input type="hidden" id="id" name="id" value="${vo.id}"/>
        
        <table class="index-content-table-add">
                td>
            tr>
            <tr>
                <td width="12%">状态:td>
                <td>
                      空闲    
                      已入住    
                td>
            tr>
            <tr>
        request.getSession().setAttribute("list", map.get("list"));

        Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
        String pageNum = Util.decode(request, "pageNum");//封装分页参数
        com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
        params.put("startIndex", pb.getStartIndex());
        params.put("pageSize", pb.getPageSize());
        List list = (List) lodgingService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
        pb.setServlet("LodgingServlet");
        pb.setSearchColumn(searchColumn);
        pb.setKeyword(keyword);
        pb.setList(list);
        request.getSession().setAttribute("pageBean", pb);
            response.sendRedirect("lodging_" + to + ".jsp");
        } else {//默认去列表页面
            this.redirectList(request, response);
        }
    }

    /**
     * 处理Get请求
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);//Get请求和Post请求的处理是一样的,所以把request、response转交给Post方法就好
    }

    /**
     * 根据参数,查询出条例条件的记录集合,最后将数据返回给调用处或者将数据集合设置到session域里,再跳转到对应的列表页面
     * 处理Get请求
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);//Get请求和Post请求的处理是一样的,所以把request、response转交给Post方法就好
    }

            params.put("keyword", username);
            params.put("startIndex", 0);
            params.put("pageSize", Long.MAX_VALUE);
            List<User> list = (List<User>) userService.list(params).get("list");
            for (User user : list) {
                if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册
                    request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");
                    request.getRequestDispatcher("register.jsp").forward(request, response);
                    return;
                }
            }
            User vo = new User();
            vo.setUsername(username);
            vo.setPassword(password);
            //vo.setUserType("普通用户");//需要设置一个默认值
            userService.add(vo);
            ps.setString(5, vo.getUserPhone());
            ps.setString(6, vo.getUserText());
            ps.setString(7, vo.getUserType());
            ps.setLong(8, vo.getId());
            ps.execute();
            ps.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
     */
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);//Get请求和Post请求的处理是一样的,所以把request、response转交给Post方法就好
    }

    /**
     * 根据参数,查询出条例条件的记录集合,最后将数据返回给调用处或者将数据集合设置到session域里,再跳转到对应的列表页面
     *
     * @param request
     * @param response
     */
    private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //查询列和关键字
<head>
    <meta charset="utf-8"/>
    <title>修改客房title>
    <link rel="stylesheet" type="text/css" href="css/index.css"/>
head>
<body>
<jsp:include page="menu.jsp"/>
<div class="index-content">
    <div class="index-content-operation">
        <a class="info-detail">修改客房a>
        <br>
        <br>
    div>
    <br>
/**
 * 住宿模块的DAO层(数据层)的具体实现类,对LodgingDAO接口中定义的增删改查等抽象方法作出具体的功能实现
 */
public class LodgingDAOImpl implements LodgingDAO {

    //@Override
    public void add(Lodging vo) {
        String sql = "insert into `t_lodging` (`lodging_name`,`lodging_sex`,`lodging_id`,`lodging_phone`,`lodging_roomno`,`lodging_start`,`lodging_end`,`lodging_price`,`lodging_text`) values(?,?,?,?,?,?,?,?,?)";
        try {
            Connection c = Util.getConnection();
            PreparedStatement ps = c.prepareStatement(sql);
            
            ps.setString(1, vo.getLodgingName());
            ps.setString(2, vo.getLodgingSex());
            ps.setString(3, vo.getLodgingId());
            ps.setString(4, vo.getLodgingPhone());
            ps.setString(5, vo.getLodgingRoomno());
            ps.setString(6, vo.getLodgingStart());
            ps.setString(7, vo.getLodgingEnd());
            ps.setString(8, vo.getLodgingPrice());
            ps.setString(9, vo.getLodgingText());
            ps.execute();

运行环境

Java≥6、Tomcat≥7.0、MySQL≥5.5

开发工具

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

技术框架

JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap.

基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可

适用

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

功能说明

登录、注册、退出、用户模块、公告模块、商品模块、住宿模块、客房模块的增删改查管理

基于javaweb+jsp的酒店管理系统_第1张图片

基于javaweb+jsp的酒店管理系统_第2张图片

基于javaweb+jsp的酒店管理系统_第3张图片

基于javaweb+jsp的酒店管理系统_第4张图片

基于javaweb+jsp的酒店管理系统_第5张图片

基于javaweb+jsp的酒店管理系统_第6张图片

基于javaweb+jsp的酒店管理系统_第7张图片

基于javaweb+jsp的酒店管理系统_第8张图片

基于javaweb+jsp的酒店管理系统_第9张图片

基于javaweb+jsp的酒店管理系统_第10张图片

基于javaweb+jsp的酒店管理系统_第11张图片

基于javaweb+jsp的酒店管理系统_第12张图片

↖[获取源码方式]见左侧

你可能感兴趣的:(javaweb,jsp,mysql,servlet,ssm)