JavaWeb: Implementing a Hotel Management System (Course Design Full Version)

foreword

The system is a hotel management system based on JavaWeb.
The front-end uses html+css+js+jQuery;
the back-end Http protocol, Servlet foundation, JSP technology, Mysql, etc.
The code of this project is relatively simple and not too complicated, which is suitable for reference by students in school.
The project source code and picture materials are attached at the end of the article.

1. Function overview

First briefly introduce a function of this project.
The project is divided into two major parts: normal users and administrators.
Ordinary users: Register and log in to the account, view and modify their personal information, view their reservation records, view other room conditions and make reservations.
Administrator: View all guest room information, can add, modify, remove, and query rooms, and can also reserve rooms on behalf of users, cancel reservations and other functions.
insert image description here

2. Code Analysis

insert image description here

  1. Action layer: manage business scheduling and jump management, that is, deal with logic problems
  2. bean layer: encapsulate data, set data properties and behavior
  3. biz layer: accept the processing results of the database and return to the front end
  4. Dao layer: add, delete, modify and check the database
  5. util layer: is a multi-purpose, tool-based package. Such as string processing, JDBC connection, etc.

3. Project display

1. Select the login entry page

insert image description here

2. Login page

insert image description here

3. Administrator room management page

insert image description here

4. Add room information

insert image description here

5. Modify room information

insert image description here

6. Personal reservation information for ordinary users

insert image description here

7. View and modify personal information of ordinary users

insert image description here

Fourth, part of the code display

1. Login and Registration

//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. View and save personal information

 // 获取 用户名
        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. Room reservation

 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. Database connection

<?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>

5. Project Summary

The writing of the web is relatively simple. The general idea of ​​writing is: write the front-end page first, and then pass the information to the back-end. The back-end processes the data, and then forwards the data to the front-end after processing. This can be repeated. If there is a problem, you can point it out in the comment area.

6. Source code display

Link: https://pan.baidu.com/s/1DCRWKfFXQKLt61FKDfBpVg?pwd=ojbk
Extraction code: ojbk

Guess you like

Origin blog.csdn.net/m0_63512120/article/details/130713572