0


基于Java Web的酒店管理系统

1.系统概述

此次系统功能较为简单。开发模式为:JSP+Servlet+JavaBean,另外需要MyElicpe、MySQL、Tomact服务器等。

2.系统功能

本系统主要功能是管理员进行日常酒店管理操作,例如登记住房信息、查询客房信息、修改客房信息、删除客房信息、添加客房信息,另外是结算退房功能。

3.所用数据库表

1.user(员工表)

2.member(会员表)

3.house(房型表)

4.具体功能实现

4.1 登录功能

login.jsp

<body background="image/3.jpg">
    <form name="form1" action="loginservlet?method=login" method="post">
        <p id=jerry>酒店管理系统</p>
        <table width="300" border="1" align="center" height="200">
            <tr id="tb">
                <td colspan="2" align="center">系统登录</td>
            </tr>
            <tr id="tb">
                <td>工号</td>
                <td><input type="text" name="username" size="20"></td>
            </tr>
            <tr id="tb">
                <td>密码</td>
                <td><input type="password" name="password" size="20"></td>
            </tr>
            <tr>
            </tr>
            <tr id="tb">
                <td colspan="2"><input type="submit" name="submit" value="登录">
                    <a href="register.jsp">注册新用户</a></td>
            </tr>
        </table>
    </form>

</body>

register.jsp

<body background="image/3.jpg">
    <form name="form1" action="loginservlet?method=register" method="post">
        <p id=jerry>酒店管理系统</p>
        <table width="300" border="1" align="center">
            <tr>
                <td colspan="2" align="center">注册窗口</td>
            </tr>
            <tr>
                <td>用户名</td>
                <td><input type="text" name="username"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" name="password1"></td>
            </tr>
            <tr>
                <td>确认密码</td>
                <td><input type="password" name="password2"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td><input type="text" name="email"></td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" name="submit" value="注册">
                    <a href="login.jsp">返回</a></td>
            </tr>
        </table>
    </form>
</body>

loginServlet

@WebServlet(urlPatterns="/loginservlet")
public class loginServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO 自动生成的方法存根
        String method=request.getParameter("method");
        if("login".equals(method)){
            doLogin(request,response);
        }
        else if("logout".equals(method)){
            doLogout(request,response);
        }
        else if("register".equals(method)){
            doAdd(request,response);
        }

    }
    //用户注册
    private void doAdd(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String username=request.getParameter("username");
        String password1=request.getParameter("password1");
        String password2=request.getParameter("password2");
        String email=request.getParameter("email");
        if(!"".equals(username)&&password1.equals(password2)){
            UserBean user_bean=new UserBean();
            user_bean.add(username, password1, email);
            System.out.println("注册成功!");
            response.sendRedirect("login.jsp");
        }
        else {
            System.out.println("注册失败!");
            response.sendRedirect("login.jsp");
        }
    }
    //登录
    private void doLogin(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        UserBean user_bean=new UserBean();
        if(user_bean.isExist(username)){
            if(user_bean.valid(username, password)){
                HttpSession session=request.getSession();
                session.setAttribute("username",username);
                System.out.println("登录成功");
                response.sendRedirect("welcome.jsp");
            }
            else {//密码错误
                System.out.println("登录失败1");
                response.sendRedirect("login.jsp");
            }
        }
        else {
            System.out.println("登录失败2");
            response.sendRedirect("login.jsp");
        }
    }
    //退出登录
    protected void doLogout(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        session.removeAttribute("username");
        System.out.println("退出成功");
        response.sendRedirect("login.jsp");
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        doGet(request, response);
    }
}

4.2 欢迎页面

welcome.jsp

<body background="image/3.jpg">

    <table width="100%">
        <p id="ss" class="text">酒店管理系统</p>
        <%
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat format = new SimpleDateFormat("dd日-MM月-yyyy年 HH:mm:ss");
        %>
        <tr>
            <td colspan="2" align="right">登陆成功!欢迎你,<%=(String) session.getAttribute("username")%>
            </td>
            <td align="right">
                <%
                    out.println(format.format(cal.getTime()));
                %>
            </td>
        </tr>

        <tr>
            <td colspan="3">
                <hr>
            </td>
        </tr>
        <tr>
            <td><br> <br> <br> <br> <br> <br>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <form name="form1" action="loginservlet?method=logout" method="post">
                    <table width="450" height="300" border="1" align="center" id="tom">
                        <tr>
                            <th colspan="3" align="center">选择功能</th>
                        </tr>
                        <tr>
                            <td><a class="a" href="pageservlet?method=showHouse">客房列表</a></td>

                            <td><a class="a" href="addhouse.jsp">添加客房</a></td>
                        </tr>
                        <tr>
                            <td><a class="a" href="inhouse.jsp">住房登记</a></td>

                            <td><a class="a" href="pageservlet?method=showMember">退房登记</a></td>
                        </tr>
                        <tr>
                            <td colspan="3" align="center"><input type="submit"
                                name="submit" value="退出"></td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>

        </div>
</body>

4.3 客房列表功能

hotelBean.java

public class hotel {
private String name;//房间名称
private int price;//房间价格
private int amount;//房间价格
private String square;//房间面积
private int people;//房间可住人数
public final static int maxpage=4;
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getPrice() {
    return price;
}
public void setPrice(int price) {
    this.price = price;
}
public int getAmount() {
    return amount;
}
public void setAmount(int amount) {
    this.amount = amount;
}
public String getSquare() {
    return square;
}
public void setSquare(String square) {
    this.square = square;
}
public int getPeople() {
    return people;
}
public void setPeople(int people) {
    this.people = people;
}
}

houseDao

public class houseDao {
    DBAccess db=new DBAccess();
    public ArrayList<hotel>allhotel(){//显示全部房间
        ArrayList<hotel>list=new ArrayList<hotel>();
        if(db.createConn()){
            String sql="select * from house";
            try {
                db.query(sql);
                while(db.next()){
                    hotel ho=new hotel();
                    ho.setName(db.getRs().getString("name"));
                    ho.setPrice(db.getRs().getInt("price"));
                    ho.setAmount(db.getRs().getInt("amount"));
                    ho.setSquare(db.getRs().getString("square"));
                    ho.setPeople(db.getRs().getInt("people"));
                    list.add(ho);
                }

            } catch (SQLException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            finally {
                db.closeRs();
                db.closeStm();
                db.closeConn();
            }
        }
        return list;
    }
    public hotel show(String name){//显示房间信息
        hotel ho=new hotel();
        if(db.createConn()){
            String sql="select * from house where name=?";
            try {
                db.pre=db.getConn().prepareStatement(sql);
                db.pre.setString(1, name);
                db.setRs(db.pre.executeQuery());
                if(db.getRs().next()){

                    ho.setName(db.getRs().getString("name"));
                    ho.setPrice(db.getRs().getInt("price"));
                    ho.setAmount(db.getRs().getInt("amount"));
                    ho.setSquare(db.getRs().getString("square"));
                    ho.setPeople(db.getRs().getInt("people"));
                }
            } catch (SQLException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            finally {
                db.closeRs();
                if(db.pre!=null){
                    try {
                        db.pre.close();
                    } catch (SQLException e) {
                        // TODO 自动生成的 catch 块
                        e.printStackTrace();
                    }
                    db.closeConn();
                }
            }
        }
        return ho;
    }
    public boolean updatehotel(hotel ho) throws Exception{//修改房间  
        boolean flag = false;
        DBAccess db=new DBAccess();
        if(db.createConn()){
            String sql="UPDATE house SET name=?,price=?,amount=?,square=?,people=? where name=?";
            db.pre=db.getConn().prepareStatement(sql);
            db.pre.setString(1, ho.getName());
            db.pre.setInt(2, ho.getPrice());
            db.pre.setInt(3, ho.getAmount());
            db.pre.setString(4, ho.getSquare());
            db.pre.setInt(5, ho.getPeople());
            db.pre.setString(6, ho.getName());
            if(db.pre.executeUpdate() > 0) flag = true;
        }
        db.closeRs();
        db.closeStm();
        db.pre.close();
        db.closeConn();
        return flag;
    }
    public boolean updateamount(hotel ho){//更新房间数量
        boolean flag = false;
        DBAccess db=new DBAccess();
        if(db.createConn()){
            String sql="update house set amount=? where name=?";
            try {
                db.pre=db.getConn().prepareStatement(sql);
                db.pre.setInt(1,ho.getAmount() );
                db.pre.setString(2, ho.getName());
                if(db.pre.executeUpdate()>0) flag=true;
            } catch (SQLException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }finally {
                try {
                    db.pre.close();
                } catch (SQLException e) {
                    // TODO 自动生成的 catch 块
                    e.printStackTrace();
                }
                db.closeConn();
            }
        }
        return flag;
    }
    public boolean add(hotel ho) throws Exception{//添加房间
        boolean flag = false;
        DBAccess db=new DBAccess();
        if(db.createConn()){
            String sql = "INSERT INTO house(name,price,amount,square,people) VALUES(?,?,?,?,?)";
            db.pre=db.getConn().prepareStatement(sql);
            db.pre.setString(1, ho.getName());
            db.pre.setInt(2, ho.getPrice());
            db.pre.setInt(3, ho.getAmount());
            db.pre.setString(4, ho.getSquare());
            db.pre.setInt(5, ho.getPeople());
            if(db.pre.executeUpdate() > 0) flag = true;
        }
        db.closeRs();
        db.closeStm();
        db.pre.close();
        db.closeConn();
        return flag;
    }
    public boolean delHouse(String name) throws Exception{//删除房间
        DBAccess db=new DBAccess();
        boolean flag = false;
        String sql="DELETE FROM house WHERE name = ?";
        if(db.createConn()){
            db.pre=db.getConn().prepareStatement(sql);
            db.pre.setString(1, name);
            if(db.pre.executeUpdate()>0)flag=true;
        }
        db.closeConn();
        db.closeStm();
        db.pre.close();
        db.closeRs();
        return flag;
    }
    public ArrayList<hotel> findAll(Integer page){//分页查询信息
        DBAccess  db=new DBAccess();
        ArrayList<hotel> list=new ArrayList<hotel>();
        
        try {
            if(db.createConn()){
                String sql="select  * from house limit ?,? ";
                db.pre=db.getConn().prepareStatement(sql);
                db.pre.setInt(1, (page-1)*hotel.maxpage);
                db.pre.setInt(2, hotel.maxpage);
                db.setRs(db.pre.executeQuery());
                while(db.getRs().next()){
                    hotel ho=new hotel();
                    ho.setName(db.getRs().getString("name"));
                    ho.setPrice(db.getRs().getInt("price"));
                    ho.setAmount(db.getRs().getInt("amount"));
                    ho.setSquare(db.getRs().getString("square"));
                    ho.setPeople(db.getRs().getInt("people"));
                    list.add(ho);
                }
                db.closeRs();
                db.pre.close();
                db.closeConn();
            }
        } catch( SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public int countPage(){//查询记录总数
        DBAccess  db=new DBAccess();
        int count=0;
        try {
            if(db.createConn()){
                String sql="select count(*) from house  ";
                db.pre=db.getConn().prepareStatement(sql);
                db.setRs(db.pre.executeQuery());
                if(db.getRs().next()){
                    count=db.getRs().getInt(1);
                }
            }
        } catch( SQLException e) {
            e.printStackTrace();
        }
        finally {
            db.closeRs();
            try {
                if(db.pre!=null){
                    db.pre.close();
                }
            } catch (Exception e2) {
                // TODO: handle exception
            }
            db.closeConn();
        }
        return count;
    }
}

housemanageServlet

@WebServlet(urlPatterns="/houseServlet")
public class housemanageServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String method=request.getParameter("method");
        if("show".equals(method)){
            doShow(request,response);
        }
        else if("add".equals(method)){
            doAdd(request,response);
        }
        else if("show2".equals(method)){
            doShow2(request,response);
        }
        else if("update".equals(method)){
            doUpdate(request,response);
        }
        else if("update2".equals(method)){
            doUpdate2(request,response);
        }
        else if("delete".equals(method)){
            doDel(request,response);
        }

    }
    //删除客房
    private void doDel(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("category");
        houseDao house=new houseDao();
        try {
            if(house.delHouse(name)){
                System.out.println("删除成功!");
                response.sendRedirect("showhouse.jsp");//删除之后无法立马更新数据
                return;
            }
            else {
                System.out.println("删除失败!");
                response.sendRedirect("showhouse.jsp");
            }
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }
    //修改客房信息
    private void doUpdate2(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException  {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("name");
        int price=Integer.parseInt(request.getParameter("price"));
        int amount=Integer.parseInt(request.getParameter("amount"));
        String square=request.getParameter("square");
        int people=Integer.parseInt(request.getParameter("people"));
        houseDao house=new houseDao();
        hotel ho=new hotel();
        ho.setName(name);
        ho.setPrice(price);
        ho.setAmount(amount);
        ho.setSquare(square);
        ho.setPeople(people);
        try {
            if(house.updatehotel(ho)){
                System.out.println("修改成功!");
                response.sendRedirect("showhouse.jsp");
                return;
            }
            else {
                System.out.println("修改失败!");
                response.sendRedirect("showhouse.jsp");
            }
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }
    //用来重定向到修改页面
    private void doUpdate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//重定向到 update.jsp
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("category");
        houseDao house=new houseDao();
        hotel ho=house.show(name);
        request.setAttribute("ho", ho);
        request.getRequestDispatcher("update.jsp").forward(request, response);
    }
    //显示客房具体信息
    private void doShow2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("category");
        houseDao house=new houseDao();
        hotel ho=house.show(name);
        HttpSession session=request.getSession();
        session.setAttribute("ho", ho);
        response.sendRedirect("showhouse2.jsp");
    }
    //添加客房
    private void doAdd(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("name");
        int price=Integer.parseInt(request.getParameter("price"));
        int amount=Integer.parseInt(request.getParameter("amount"));
        String square=request.getParameter("square");
        int people=Integer.parseInt(request.getParameter("people"));
        houseDao house=new houseDao();
        hotel ho=new hotel();
        if(!"".equals(name)&&!"".equals(square)&&0!=price&&0!=amount&&people!=0){
            ho.setName(name);
            ho.setPrice(price);
            ho.setAmount(amount);
            ho.setSquare(square);
            ho.setPeople(people);
        }
        else {
            System.out.println("添加失败,信息不全");
            response.sendRedirect("addhouse.jsp");
        }
        try {
            if(house.add(ho)){
                System.out.println("添加成功!");
                response.sendRedirect("addhouse.jsp");
            }
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }
    //显示所有客房信息
    private void doShow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        // TODO 自动生成的方法存根
        houseDao house_dao=new houseDao();
        ArrayList<hotel> house=house_dao.allhotel();
        HttpSession session=request.getSession();
        session.setAttribute("house", house);
        response.sendRedirect("showhouse.jsp");
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO 自动生成的方法存根
        doGet(request, response);
    }
}

showhouse.jsp(全部)

<body background="image/3.jpg">
    <table width="100%">
        <p id="ss">酒店管理系统</p>
        <%
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat format = new SimpleDateFormat("dd日-MM月-yyyy年 HH:mm:ss");
        %>
        <tr>
            <td colspan="2" align="right">登陆成功!欢迎你,<%=(String) session.getAttribute("username")%>
            </td>
            <td align="right">
                <%
                    out.println(format.format(cal.getTime()));
                %>
            </td>
        </tr>

        <tr>
            <td colspan="3">
                <hr>
            </td>
        </tr>
        <tr>
            <td><a href="welcome.jsp">返回</a></td>
        </tr>
        <tr>
            <td><br> <br> <br> <br> <br> <br>
            </td>
        </tr>
    </table>
    <h2 align="center">所有客房信息</h2>
    <table width="400" height="200" border="1" align="center">
        <tr>
            <td align="center">房间类型</td>
            <td align="center">房型价格</td>
            <td align="center">可预定数量</td>
            <td align="center">操作</td>
        </tr>
        <%
            for (hotel ho : hotels) {
        %>
        <tr>
            <td align="center"><%=ho.getName()%></td>
            <td align="center"><%=ho.getPrice()%>¥</td>
            <td align="center"><%=ho.getAmount()%></td>
            <td><a
                href="houseServlet?method=show2&category=<%=ho.getName()%>">查看</a>
                <a href="houseServlet?method=update&category=<%=ho.getName()%>">修改</a>
                <a href="houseServlet?method=delete&category=<%=ho.getName()%>">删除</a>
            </td>
        </tr>
        <%
            }
        %>
        <tr>
            <td align="center" colspan="6" bgcolor="gray">
                <%--<%=request.getAttribute("bar")  /页 --%> ${bar}/页
            </td>
        </tr>
    </table>
</body>

4.4 查看房型详细信息

4.5 修改客房信息

4.6 添加客房信息

4.7 住房登记

memberBean.java

public class member {
private String name;//会员名
private String tel;//手机号
private String category;//房间类型
private String hotelnumber;//房间号
private int people;//入住人数
private String money;//消费
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getTel() {
    return tel;
}
public void setTel(String tel) {
    this.tel = tel;
}
public String getCategory() {
    return category;
}
public void setCategory(String category) {
    this.category = category;
}
public String getHotelnumber() {
    return hotelnumber;
}
public void setHotelnumber(String hotelnumber) {
    this.hotelnumber = hotelnumber;
}
public int getPeople() {
    return people;
}
public void setPeople(int people) {
    this.people = people;
}
public String getMoney() {
    return money;
}
public void setMoney(String money) {
    this.money = money;
}

}

memberDao

public class memberDao {
    DBAccess db=new DBAccess();

    public boolean add(member me) throws Exception{//添加会员
        boolean flag = false;
        if(db.createConn()){
            String sql = "INSERT INTO member(name,tel,category,hotelnumber,people,money) VALUES(?,?,?,?,?,?)";
            db.pre=db.getConn().prepareStatement(sql);
            db.pre.setString(1, me.getName());
            db.pre.setString(2, me.getTel());
            db.pre.setString(3, me.getCategory());
            db.pre.setString(4, me.getHotelnumber());
            db.pre.setInt(5, me.getPeople());
            db.pre.setString(6, me.getMoney());
            if(db.pre.executeUpdate() > 0) flag = true;
        }
        db.closeRs();
        db.closeStm();
        db.pre.close();
        db.closeConn();
        return flag;
    }
    public ArrayList<member> allmember(){//显示所有会员
        ArrayList<member>list=new ArrayList<member>();
        if(db.createConn()){
            String sql="select * from member";
            try {
                db.query(sql);
                while(db.next()){
                    member me=new member();
                    me.setName(db.getRs().getString("name"));
                    me.setTel(db.getRs().getString("tel"));
                    me.setCategory(db.getRs().getString("category"));
                    me.setHotelnumber(db.getRs().getString("hotelnumber"));
                    me.setPeople(db.getRs().getInt("people"));
                    me.setMoney(db.getRs().getString("money"));
                    list.add(me);
                }
            } catch (SQLException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            finally {
                db.closeRs();
                db.closeStm();
                db.closeConn();
            }
        }
        return list;
    }
    public member showpersonal(String name){//显示会员详细信息
        member me=new member();
        if(db.createConn()){
            String sql="select * from member where name=?";
            try {
                db.pre=db.getConn().prepareStatement(sql);
                db.pre.setString(1, name);
                db.setRs(db.pre.executeQuery());
                if(db.getRs().next()){

                    me.setName(db.getRs().getString("name"));
                    me.setTel(db.getRs().getString("tel"));
                    me.setCategory(db.getRs().getString("category"));
                    me.setHotelnumber(db.getRs().getString("hotelnumber"));
                    me.setPeople(db.getRs().getInt("people"));
                    me.setMoney(db.getRs().getString("money"));
                }
            } catch (SQLException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            finally {
                db.closeRs();
                if(db.pre!=null){
                    try {
                        db.pre.close();
                    } catch (SQLException e) {
                        // TODO 自动生成的 catch 块
                        e.printStackTrace();
                    }
                    db.closeConn();
                }
            }
        }
        return me;
    }
    public boolean delMember(String tel) throws Exception{//删除会员信息
        DBAccess db=new DBAccess();
        boolean flag = false;
        String sql="DELETE FROM member WHERE tel = ?";
        if(db.createConn()){
            db.pre=db.getConn().prepareStatement(sql);
            db.pre.setString(1, tel);
            if(db.pre.executeUpdate()>0)flag=true;
        }
        db.closeConn();
        db.closeStm();
        db.pre.close();
        db.closeRs();
        return flag;
    }
    public ArrayList<member> findAll(Integer page){//分页查询信息
        DBAccess  db=new DBAccess();
        ArrayList<member> list=new ArrayList<member>();
        
        try {
            if(db.createConn()){
                String sql="select  * from member limit ?,? ";
                db.pre=db.getConn().prepareStatement(sql);
                db.pre.setInt(1, (page-1)*hotel.maxpage);
                db.pre.setInt(2, hotel.maxpage);
                db.setRs(db.pre.executeQuery());
                while(db.getRs().next()){
                    member me=new member();
                    me.setName(db.getRs().getString("name"));
                    me.setTel(db.getRs().getString("tel"));
                    me.setCategory(db.getRs().getString("category"));
                    me.setHotelnumber(db.getRs().getString("hotelnumber"));
                    me.setPeople(db.getRs().getInt("people"));
                    me.setMoney(db.getRs().getString("money"));
                    list.add(me);
                }
                db.closeRs();
                db.pre.close();
                db.closeConn();
            }
        } catch( SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public int countPage(){//查询记录总数
        DBAccess  db=new DBAccess();
        int count=0;
        try {
            if(db.createConn()){
                String sql="select count(*) from member  ";
                db.pre=db.getConn().prepareStatement(sql);
                db.setRs(db.pre.executeQuery());
                if(db.getRs().next()){
                    count=db.getRs().getInt(1);
                }
            }
        } catch( SQLException e) {
            e.printStackTrace();
        }
        finally {
            db.closeRs();
            try {
                if(db.pre!=null){
                    db.pre.close();
                }
            } catch (Exception e2) {
                // TODO: handle exception
            }
            db.closeConn();
        }
        return count;
    }
}

membermanageServlet

@WebServlet(urlPatterns="/membermanage")
public class membermanageServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String method=request.getParameter("method");
        if("inroom".equals(method)){
            doInroom(request,response);
        }
        else if ("outroom".equals(method)) {
            doOutroom(request,response);
        }
        else if("personalmessage".equals(method)){
            doShowPerMessage(request,response);
        }
        else if("delmember".equals(method)){
            doDelMember(request,response);
        }
    }
    //退房操作
    private void doDelMember(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String tel=request.getParameter("tel");
        String category=request.getParameter("category");
        houseDao house=new houseDao();
        memberDao member=new memberDao();
        hotel ho=null;
        try {
            if(member.delMember(tel)){
                ho=house.show(category);
                ho.setAmount(ho.getAmount()+1);//获取房型相关信息
                house.updateamount(ho);
                System.out.println("退房成功!");
                response.sendRedirect("welcome.jsp");
                return;
            }
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }
    //显示会员信息
    private void doShowPerMessage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("name");
        memberDao member=new memberDao();
        member mb=member.showpersonal(name);
        HttpSession session=request.getSession();
        session.setAttribute("mb", mb);
        //request.setAttribute("mb", mb);
        response.sendRedirect("showmemberMassage.jsp");
        //request.getRequestDispatcher("showmemberMassage.jsp").forward(request, response);

    }
    //住房登记
    private void doInroom(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("name");
        String tel=request.getParameter("tel");
        String category=request.getParameter("category");
        String housenumber=request.getParameter("housenumber");
        int people=Integer.parseInt(request.getParameter("people"));
        String money=request.getParameter("money");
        memberDao member =new memberDao();
        houseDao house=new houseDao();
        hotel ho=null;
        if(name!=null&&tel!=null&&category!=null&&housenumber!=null&&people!=0&&money!=null){
            member me=new member();
            me.setName(name);
            me.setTel(tel);
            me.setCategory(category);
            me.setHotelnumber(housenumber);
            me.setPeople(people);
            me.setMoney(money);
            try {
                ho=house.show(category);//根据房间类型获取房间
                if(member.add(me)&&ho.getAmount()>0){
                    //System.out.println("添加会员成功!");
                    ho.setAmount(ho.getAmount()-1);
                    house.updateamount(ho);//更改房间数量
                    System.out.println("添加会员成功!");
                    response.sendRedirect("welcome.jsp");
                }
                else {
                    System.out.println("添加会员失败,没有可用的房间!");
                    response.sendRedirect("inhouse.jsp");
                }
            } catch (Exception e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
        }
        else {
            System.out.println("添加会员失败,信息不全!");
            response.sendRedirect("inhouse.jsp");
        }
    }
    //退房登记
    private void doOutroom(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        // TODO 自动生成的方法存根
        memberDao member=new memberDao();
        ArrayList<member> me=member.allmember();
        HttpSession session=request.getSession();
        session.setAttribute("me", me);
        response.sendRedirect("outhouse.jsp");
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO 自动生成的方法存根
        request.setCharacterEncoding("utf-8");
        doGet(request, response);
    }
}

4.8 退房登记

4.9 会员信息详情

初入java web很多知识还没有深入,对本系统有很多不足的地方,功能也比较单一,在后面会陆续对本系统功能进一步完善,如有不妥的地方,欢迎大家交流!



本文转载自: https://blog.csdn.net/qq_52705208/article/details/125237343
版权归原作者 一颗大白菜~ 所有, 如有侵权,请联系我们删除。

“基于Java Web的酒店管理系统”的评论:

还没有评论