作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
酒店管理系统共分为三个角色,客房经理、前台管理员、客户,各个角色的权限各不相同;
客房经理功能包括:登录、注册、前台用户管理、客房管理、优惠活动、查看留言、更换客房、房费续交、订单查看、报修统计、入驻统计、退房等功能;
前台管理员主要功能:
前台管理:包括客房查询、更换客房、房费续交、订单查看、报修统计、入住统计、退房、查看留言;
客户主要功能:
主要查看用户信息:个人信息、优惠活动、客房信息、订单管理、留言等;
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
技术栈
1. 后端:Servlet
2. 前端:JSP+bootstrap+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/SLH 登录 注:tomcat中配置项目路径必须为/SLH,否则会报错;
客房经理用户名密码:admin/admin
前台管理员用户名密码:test/123456
客户用户名密码:jack/123456
运行截图
相关代码
CustomerServlet
package com.slh.code.servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.regex.Pattern;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import com.slh.code.Users;import com.slh.code.db.DBHelper;import com.slh.util.DateUtil;import com.slh.util.Keys;public class CustomerServlet extends HttpServlet {private static final long serialVersionUID = 1L;public void destroy() {super.destroy(); }public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");PrintWriter out = response.getWriter();int state = 0;String value = "";String cause = "";String result = "";String flag = request.getParameter("flag")==null?"":request.getParameter("flag");if(flag.equals("")){state = 0;result = "error:参数错误!";}else if(flag.equals("customerInfo")){result = customerInfo(request,response);}else if(flag.equals("motifyuser")){//修改用户信息result = motifyuser(request,response);}else if(flag.equals("orderRoom")){result = orderRoom(request,response);}else if(flag.equals("orderLook")){result = orderLook(request,response);}else if(flag.equals("findOrderById")){//获取单个订单信息result = findOrderById(request,response);}else if(flag.equals("editOrder")){result = editOrder(request,response);}else if(flag.equals("deleteOrder")){result = deleteOrder(request,response);}else if(flag.equals("message")){//留言result = message(request,response);}if(result.indexOf("error")!=-1){state = 0;value = result.substring(6,result.length());}else{state = 1;value =result;}System.out.println(value);out.println("{\"state\":\""+state+"\",\"value\":\""+value.replaceAll("\"", "'")+"\",\"cause\":\""+cause+"\"}");out.flush();out.close();}private String findOrderById(HttpServletRequest request,HttpServletResponse response) {String id = request.getParameter("id")==null?"":request.getParameter("id");String uid = ((Users)request.getSession().getAttribute("user")).getId();String sql = "select o.id,o.orderno,u.name,o.occupancytime,o.ordertime,o.ordermoney,o.prepay,o.ordertype,o.roomno,o.day,o.isoccupancy from orders o,users u where u.id = o.orderuser and o.id = ? and u.id = ?";String fields[]={"id","orderno","name","occupancytime","ordertime","ordermoney","prepay","ordertype","roomno","day","isoccupancy"};Map<String,String> map = new DBHelper().queryObject(sql, new String[]{id,uid}, fields);if(map!=null && !map.isEmpty()){return JSONObject.fromObject(map).toString();}else return "error:获取您的订单信息失败!";}private String motifyuser(HttpServletRequest request,HttpServletResponse response) {String id = request.getParameter("id")==null?"":request.getParameter("id");String age = request.getParameter("age")==null?"":request.getParameter("age");String sex = request.getParameter("sex")==null?"":request.getParameter("sex");String realname = request.getParameter("realname")==null?"":request.getParameter("realname");String phone = request.getParameter("phone")==null?"":request.getParameter("phone");String reg = "^[1-9]+$";Pattern p = pile(reg);if(id.equals("")) return "error:用户ID为空!";if(age.equals("")) return "error:年龄为空";if(!p.matcher(age).matches()) return "error:请输入正确的年龄";if(Integer.parseInt(age)>150) return "error:请输入真实的年龄";if(sex.equals("")) return "error:请选择性别!";if(realname.equals("")) return "error:真实姓名为空!";if(phone.equals("")) return "error:联系方式为空";String sql = "update users set age =?,sex=?,realname=?,phone=? where id= ?";String params[]={age,sex,realname,phone,id};int rows = new DBHelper().alertData(sql, params);if(rows > 0){Users u = (Users)request.getSession().getAttribute("user");u.setAge(age);u.setSex(sex);u.setRealname(realname);u.setPhone(phone);return "修改信息成功!";} else return "error:修改信息失败!";}private String message(HttpServletRequest request,HttpServletResponse response) {String id = Keys.createKey("M");String title = request.getParameter("title")==null?"":request.getParameter("title");String content = request.getParameter("content")==null?"":request.getParameter("content");String messageuser = ((Users)request.getSession().getAttribute("user")).getId();String time = DateUtil.dateFormat();if(title.equals("")) return "error:标题不能为空!";if(content.equals("")) return "error:内容不能为空!";String sql = "insert into message(id,title,content,messageuser,time)values(?,?,?,?,?)";String params[]={id,title,content,messageuser,time};int rows = new DBHelper().alertData(sql, params);if(rows >0) return "成功!";else return "error:留言失败!";}private String deleteOrder(HttpServletRequest request,HttpServletResponse response) {String id= request.getParameter("id")==null?"":request.getParameter("id");if(id.equals("")) return "error:订单ID不能为空!";String sql = "delete from orders where id = ?";String params[]={id};int rows = new DBHelper().alertData(sql, params);if(rows > 0) return "成功";else return "error:删除订单失败!";}private String editOrder(HttpServletRequest request,HttpServletResponse response) {String id = request.getParameter("id")==null?"":request.getParameter("id");String occupancytime = request.getParameter("occupancytime")==null?"":request.getParameter("occupancytime");String day = request.getParameter("day")==null?"":request.getParameter("day");if(id.equals("")) return "error:订单ID不能为空!";if(occupancytime.equals("")) return "error:入住时间不能为空!";if(day.equals("")) return "error:入住天数不能为空!";String sql = "update orders set occupancytime=? ,day =? where id =?";String params[]={occupancytime,day ,id};int rows = new DBHelper().alertData(sql, params);if(rows>0) return "订单修改成功";else return "修改订单失败!";}private String orderLook(HttpServletRequest request,HttpServletResponse response) {int page = 0;int pagesize = 5;String uid = ((Users)request.getSession().getAttribute("user")).getId();String prepage = request.getParameter("page")==null?"":request.getParameter("page");boolean p = pile("^[0-9]+$").matcher(prepage).matches();if(!p) page =1;else if(prepage.equals("")) page =1;else if(p && Integer.parseInt(prepage)>0) page = Integer.parseInt(prepage);String sql = "select o.id,o.orderno,o.occupancytime,u.name,o.ordertime ,o.ordermoney ,o.prepay,o.ordertype,o.roomno,o.day,o.isoccupancy from orders o inner join users u where o.orderuser = u.id and u.id = ? limit "+(page-1)*pagesize+","+pagesize;String csql = "select count(*) count from orders o inner join users u where o.orderuser = u.id and u.id = ? ";String params[]={uid};String total = new DBHelper().queryField(csql, params, "count");Map<String, String>map = null;if(total!=null && !total.equals("")){map = new HashMap<String, String>();int totalCount = Integer.parseInt(total);map.put("total", total);map.put("prepage", page+"");map.put("totalPage", (totalCount%pagesize==0?totalCount/pagesize:totalCount/pagesize+1)+"");String fields[]={"id","orderno","name","occupancytime","ordertime","ordermoney","prepay","ordertype","roomno","day","isoccupancy"};System.out.println("sql:"+sql);List<Map<String, String>>list = new DBHelper().queryObjects(sql, params, fields);if(list!=null && list.size()>0){list.add(map);return JSONArray.fromObject(list).toString();}elsereturn "error:没有获取到订单的信息!";}else return "error:没有获取到相关的订单信息!";}private String orderRoom(HttpServletRequest request,HttpServletResponse response) {String id = Keys.createKey("O");String orderno = Keys.createKey("SLH");String orderuser = ((Users)request.getSession().getAttribute("user")).getId();String ordertime = DateUtil.dateFormat();String ordermoney = request.getParameter("ordermoney")==null?"":request.getParameter("ordermoney");String ordertype = "1";String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");String isoccupancy = "2";String occupancytime = request.getParameter("occupancytime")==null?"":request.getParameter("occupancytime");String day = request.getParameter("day")==null?"1":request.getParameter("day");if(roomno.equals("")) return "error:房间号不能为空!";if(ordermoney.equals("")) return "error:订单价格不能为空";if(occupancytime.equals("")) return "error:入住时间不能为空!";String rsql = "update rooms set isempty = 2 where roomno = ?";int room = new DBHelper().alertData(rsql, new String[]{roomno});if(room <= 0) return "error:房间的状态修改失败!";String sql = "insert into orders(id,orderno,orderuser,ordertime,ordermoney,ordertype,roomno,isoccupancy,occupancytime,day)values(?,?,?,?,?,?,?,?,?,?)";String params[]={id,orderno,orderuser,ordertime,ordermoney,ordertype,roomno,isoccupancy,occupancytime,day};int rows = new DBHelper().alertData(sql, params);if(rows > 0) return "下单成功";else return "error:下单失败";}private String customerInfo(HttpServletRequest request,HttpServletResponse response) {if(request.getSession().getAttribute("user")!=null)return JSONObject.fromObject((Users)request.getSession().getAttribute("user")).toString();else return "error:获取用户信息失败,session失效!";}public void init() throws ServletException {}}
LoginServlet
package com.slh.code.servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.Map;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.slh.code.Users;import com.slh.code.db.DBHelper;import com.slh.util.Keys;public class LoginServlet extends HttpServlet {private static final long serialVersionUID = 1L;public void destroy() {super.destroy(); }public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {PrintWriter out = response.getWriter();int state = 0;String value = "";String cause = "";String flag = request.getParameter("flag")==null?"":request.getParameter("flag").replaceAll("[\t\n\r]", "");if(flag.equals("login")){//登陆String result = this.login(request, response);if(result.indexOf("error")!=-1){state = 0;value = result.substring(6, result.length());}else{state = 1;value = result;}}else if(flag.equals("register")){//注册String result = this.register(request, response);if(result.indexOf("error")!=-1){state = 0;value = result.substring(6, result.length());}else{state = 1;value = result;}} else if(flag.equals("exit")){//退出系统request.getSession().removeAttribute("user");if(request.getSession().getAttribute("user")!=null && !request.getSession().getAttribute("user").equals("") ){state = 0;value = "退出系统失败!";}else{state = 1;value = "成功!";}}else{state = 0;value = "参数错误!";}System.out.println("{'state':'"+state+"','value':'"+value+"','cause':'"+cause+"'}");out.println("{\"state\":\""+state+"\",\"value\":\""+value+"\",\"cause\":\""+cause+"\"}");out.close();}public String login(HttpServletRequest request, HttpServletResponse response){String username = request.getParameter("username")==null?"":request.getParameter("username").replaceAll("[\t\r\n]", "");if(username.equals("")){return "error:用户名不能为空";}String sql_name = "select name from users where name =?";String name = new DBHelper().queryField(sql_name, new String []{username}, "name");if(name == null || name.equals("")){return "error:用户名不存在!";}String password = request.getParameter("password")==null?"":request.getParameter("password").replaceAll("[\r\t\n]", "");if(password.equals("")){return "error:密码不能为空!";}String sql = "select * from users where name = ? and password = ?";String fields[] = new String[]{"id","name","age","sex","realname","role","phone","idcard"};Map<String, String>map = new DBHelper().queryObject(sql, new String[]{username,password}, fields);if(map!=null && !map.isEmpty()){Users u = new Users();u.setId(map.get("id"));u.setName(map.get("name"));u.setAge(map.get("age"));u.setSex(map.get("sex"));u.setRealname(map.get("realname"));u.setRole(map.get("role"));u.setPhone(map.get("phone"));u.setIdcard(map.get("idcard"));request.getSession().setAttribute("user", u);return "登陆成功";}else{return "error:用户密码错误!";}}public String register(HttpServletRequest request, HttpServletResponse response){String name = request.getParameter("name")==null?"":request.getParameter("name");String password = request.getParameter("password")==null?"":request.getParameter("password");String realname = request.getParameter("realname")==null?"":request.getParameter("realname");String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");String phone = request.getParameter("phone")==null?"":request.getParameter("phone");String cname = "select name from users where name = ?";String cnname = new DBHelper().queryField(cname, new String[]{name}, "name");if(cnname!=null && !cnname.equals("")) return "error:用户名重复,请修改";if(name.equals(""))return "error:用户名为空!";if(password.equals("")) return "error:密码为空!";if(realname.equals("")) return "error:真实姓名为空!";if(idcard.equals("")) return "error:身份证号码为空!";if(phone.equals("")) return "error:手机号码为空!";String id = Keys.createKey("U");String sql = "insert into users(id,name,password,realname,idcard,phone,role,isdelete) values(?,?,?,?,?,?,?,?)";String params[]={id,name,password,realname,idcard,phone,"3","0"};int rows = new DBHelper().alertData(sql, params);if(rows>0){return "注册成功";}else{return "error:注册失败!";}}public void init() throws ServletException {}public static void main(String[] args) {}}
如果也想学习本系统,下面领取。关注并回复:109jsp
如果觉得《Java项目:JSP酒店客房管理系统》对你有帮助,请点赞、收藏,并留下你的观点哦!