JavaWeb:实现酒店管理系统(课程设计完整版)

前言

该系统是一个基于JavaWeb的酒店管理系统。
前端用到了 html+css+js+jQuery;
后端Http协议,Servlet基础,JSP技术,Mysql等
这个项目的代码相对简单、不太复杂,适合在校的学生参考。
文章末尾附项目源代码和图片素材。

一、功能概述

先简单的介绍一个这个项目的功能。
项目分为两个大部分:普通用户和管理员。
普通用户:注册和登陆账号,查看和修改自己的个人信息、查看自己的预约记录,查看其他客房情况并且可以预约。
管理员:查看所有客房信息,可以对客房进行增加、修改、下架、查询功能,也可以代替用户预约客房,取消预约等功能。
在这里插入图片描述

二、代码分析

在这里插入图片描述

  1. action层:管理业务调度和管理跳转的,即处理逻辑问题
  2. bean层:封装数据,设置数据的属性和行为
  3. biz层:接受数据库的处理结果并且返回给前端
  4. dao层:对数据库进行增删改查
  5. util层: 是一个多功能,基于工具的包。比如字符串处理,JDBC连接等

三、项目展示

1.选择登录入口页面

在这里插入图片描述

2.登录页面

在这里插入图片描述

3.管理员客房管理页面

在这里插入图片描述

4.添加客房信息

在这里插入图片描述

5.修改客房信息

在这里插入图片描述

6.普通用户个人预约信息

在这里插入图片描述

7.普通用户个人信息查看和修改

在这里插入图片描述

四、部分代码展示

1.登录和注册

//1.判读用户请求的类型为login
        String method = req.getParameter("type");
        switch (method) {
            case "login":
                // 从 login.html中 拿 账号,密码等数据
                String name = req.getParameter("name");
                String pwd = req.getParameter("pwd");
                //  调用UserBiz的getUser方法,根据 网页中 输入的账号密码,获取相应对象
                User user = userBiz.getUser(name,pwd);
                 //判断 获取到的对象是否为 null;
                 if (user == null) {
                     System.out.println(user);
                     out.println("<script>alert('用户名或密码不存在');location.href = 'login.html';</script>");
                 }else {
                     session.setAttribute("user",user);//user-->Object
                     out.println("<script>alert('登录成功');location.href='/UserShow';</script>");
                 }
                 break;
            case "register" :
                // 从 login.html中 拿 账号,密码等数据
                String name1 = req.getParameter("name");
                String pwd1 = req.getParameter("pwd");
                UserDao userDao = new UserDao();
                try {
                    userDao.setUser(name1,pwd1);
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
                out.println("<script>alert('注册成功');location.href = 'login.html';</script>");
                break;


2.个人信息查看和保存

 // 获取 用户名
        User user = (User) req.getSession(false).getAttribute("user");
        String name = user.getName();
        UserDao userDao = new UserDao();
        try {
            req.setAttribute("name",  userDao.getMyinformation(name).getName());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        try {
            req.setAttribute("pwd",  userDao.getMyinformation(name).getPwd());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        try {
            req.setAttribute("id",  userDao.getMyinformation(name).getId());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        try {
            req.setAttribute("age",  userDao.getMyinformation(name).getAge());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        try {
            req.setAttribute("sex",  userDao.getMyinformation(name).getSex());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        req.getRequestDispatcher("myinformation.jsp").forward(req, resp);

3.客房预定

 CommodityDao commodityDao = new CommodityDao();
        String temp = req.getParameter("booking");
        int temp1 = 0;
        if (temp!=null) {
            temp1=Integer.parseInt(temp);
        }
        String temo=req.getParameter("idd");  //  获取到的 房间 id
        String temp2 = req.getParameter("price");  // 输入的内容
        try {
            commodityDao.modstateCommodity(temo,temp2);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        req.getRequestDispatcher("/index").forward(req, resp);

4. 数据库连接

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config> <!--默认配置 -->
    <default-config>
        <!--initialPoolSize:连接池初始化时创建的连接数,default : 3,取值应在minPoolSize与 maxPoolSize之间-->
        <property name="initialPoolSize">10</property>
        <!-- maxIdleTime:连接的最大空闲时间,如果超过这个时间,某个数据库连接还没有被使用,则会断开掉这个连接。如果为0,则永远不会断开连接,即回收此连接。default : 0 单位 s -->
        <property name="maxIdleTime">30</property>
        <!--maxPoolSize:连接池中拥有的最大连接数,如果获得新连接时会使连接总数超过这个值则不会再获取新连接,而是等待其他连接释放,所以这个值有可能会设计地很大,default : 15-->
        <property name="maxPoolSize">100</property>
        <!--minPoolSize:连接池保持的最小连接数,default : 3-->
        <property name="minPoolSize">10
        </property>
        <!--maxStatements:连接池为数据源缓存的PreparedStatement的总数。由于PreparedStatement属于单 个Connection,所以这个数量应该根据应用中平均连接数乘以每个连接的平均PreparedStatement 来计算-->
        <property name="maxStatements">200</property>
    </default-config> <!--配置连接池oracle -->
    <!-- 配置mysql-->
    <named-config name="mysql-book">
	    <!--mysql需要使用的驱动类-->
        <property name="driverClass">com.mysql.jdbc.Driver</property>
		<!--连接语句-->
        <property name="jdbcUrl">jdbc:mysql://127.0.0.1:3306/mydemo?useUnicode=true&amp;characterEncoding=utf8</property>
		<!--mysql的用户名-->
        <property name="user">root</property>
		<!--我的mysql的密码:根据自己机器进行修改-->
        <property name="password">123456</property>
		<!--连接池初始化时创建的连接数:10-->
        <property name="initialPoolSize">10</property>
		<!--maxIdleTime:连接的最大空闲时间,如果超过这个时间,某个数据库连接还没有被使用,则会断开掉这个连接。-->
        <property name="maxIdleTime">30</property>
		<!--连接池中拥有的最大连接数-->
        <property name="maxPoolSize">100</property>
		<!--连接池保持的最小连接数-->
        <property name="minPoolSize">10</property>
		<!--连接池为数据源缓存的PreparedStatement的总数-->
        <property name="maxStatements">200</property>
    </named-config>
</c3p0-config>

五、项目总结

该web写的相对简单一点,写的大概思路就是:先写前端页面,然后将信息传递给后端,后端在对数据进行处理,处理之后再将数据转发给前端。如此反复即可。如果有问题了,可以在评论区指出。

扫描二维码关注公众号,回复: 15187482 查看本文章

六、源代码展示

链接:https://pan.baidu.com/s/1DCRWKfFXQKLt61FKDfBpVg?pwd=ojbk
提取码:ojbk

猜你喜欢

转载自blog.csdn.net/m0_63512120/article/details/130713572