基于javaweb的JSP+Servlet酒店客房管理系统(java+jsp+html+bootstrap+jquery+servlet+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

410023442402

420023442402

440023442402

450023442402

基于javaweb的JSP+Servlet酒店客房管理系统(java+jsp+html+bootstrap+jquery+servlet+mysql)

项目介绍

酒店管理系统共分为三个角色,客房经理、前台管理员、客户,各个角色的权限各不相同; 客房经理功能包括:登录、注册、前台用户管理、客房管理、优惠活动、查看留言、更换客房、房费续交、订单查看、报修统计、入驻统计、退房等功能;

前台管理员主要功能: 前台管理:包括客房查询、更换客房、房费续交、订单查看、报修统计、入住统计、退房、查看留言;

客户主要功能: 主要查看用户信息:个人信息、优惠活动、客房信息、订单管理、留言等;

环境需要

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	String compensationgoods = request.getParameter("compensationgoods")==null?"":request.getParameter("compensationgoods");
String cash = request.getParameter("cash")==null?"":request.getParameter("cash");
String ChangMoney = request.getParameter("ChangMoney")==null?"":request.getParameter("ChangMoney");
String time = DateUtil.dateFormat();
String reg = "^[0-9]+$";
Pattern p = Pattern.compile(reg);
if(!(p.matcher(cash)).matches()) return "error:现金格式有误!";
if(!(p.matcher(ChangMoney)).matches()) return "error:找零格式有误!";
if(id.equals("")) return "error:房间ID为空";
if(roomno.equals("")) return "error:房间号为空";
if(!otherpay.equals("") && Integer.parseInt(otherpay) > 0 && otherpaygoods.equals("")) return "error:其他费用物品不能为空!";
if(otherpay.equals("")) otherpay = "0";
if(iscompensation.equals("1")){
if(compensationmoney.equals("")) return "error:赔偿金额不能为空!";
if(compensationgoods.equals("")) return "error:赔偿物品不能为空!";
}else{
iscompensation = "2";
}

String rsql = "update rooms set isempty = 1 where roomno = ?";
int r = new DBHelper().alertData(rsql, new String[]{roomno});
if(r <=0 ) return "error:修改房间状态失败!";

String osql = "update orders set isoccupancy = 3 where id = ?";
int o = new DBHelper().alertData(osql, new String[]{id});
if(o <=0 ) return "error:修改订单状态失败!";

String sql="update orders set iscompensation=?,compensationmoney=?,compensationgoods=? ,otherpay=? ,otherpaygoods=?,cash=?,changemoney=?,outtime=? where id=?";
String params[]={iscompensation,compensationmoney,compensationgoods,otherpay,otherpaygoods,cash,ChangMoney,time,id};
int rows = new DBHelper().alertData(sql, params);
if(rows > 0) return "添加赔偿成功";
else return "添加赔偿失败!";
}

private String lookOrder(HttpServletRequest request,
HttpServletResponse response) {
String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
String name = request.getParameter("name")==null?"":request.getParameter("name");
String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");
String isoccupancy = request.getParameter("isoccupancy")==null?"":request.getParameter("isoccupancy");
String sql = "select o.id,o.orderno,u.name,o.roomno,o.handleuser,o.ordertime,o.ordermoney,o.prepay,o.ordertype,o.occupancytime,o.outtime ,o.isoccupancy,o.iscompensation,o.compensationmoney,o.compensationgoods from orders o,users u where u.id=o.orderuser and 1=1";
int page=0;
String prepage = request.getParameter("page")==null?"":request.getParameter("page");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	//获取信息
result = findOrder(request,response);
}else if(flag.equals("editOrder")){
//前台修改订单信息
result = editOrder(request,response);
}else if (flag.equals("addCusAndOrder")){
//前台添加用户和订单
result = addCusAndOrder(request,response);
}else if (flag.equals("StayCount")){
//入住统计
result = StayCount(request,response);
}else if (flag.equals("repairing")){
//报修
result = repairing(request,response);
}else if(flag.equals("repairCount")){
//报修列表
result = repairCount(request,response);
}else if (flag.equals("findRoomNoRepir")){
//获取所有的房间号
result = findRoomNo(request,response);
}else if (flag.equals("lookOrder")){
//订单查看
result = lookOrder(request,response);
}else if(flag.equals("findCheckOut")){
//获取退房信息
result = findCheckOut(request,response);
}else if(flag.equals("checkOut")){
//退房
result = checkOut(request,response);
}else if(flag.equals("findOrderByOrderId")){
//通过订单ID获取订单信息
result = findOrderByOrderId(request,response);
}else if(flag.equals("findExitUser")){
//查看用户是否存在
result = findExitUser(request,response);
}else if(flag.equals("findRoomNo")){
//获取房间号
result = findRoomNo(request,response);
}else if(flag.equals("findRoomPrice")){
//获取房间的价格
result = findRoomPrice(request,response);
}else if(flag.equals("delOrder")){
//删除订单
result = delOrder(request,response);
}else if (flag.equals("findOrderStatus")){
//查看订单状态
result = findOrderStatus(request,response);
}else if(flag.equals("cancleOrder")){
//取消订单
result = cancleOrder(request,response);
}else if(flag.equals("changeRoom")){
//换房
result = changeRoom(request,response);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46



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");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
		result = messages(request,response);
}

if(result.indexOf("error")!=-1){
state = 0;
value = result.substring(6,result.length());
}else{
state = 1;
value =result;
}
System.out.println(value.replace("\"", "'"));
out.println("{\"state\":\""+state+"\",\"value\":\""+value.replace("\"", "'")+"\",\"cause\":\""+cause+"\"}");
out.flush();
out.close();


}

private String messages(HttpServletRequest request,
HttpServletResponse response) {
String sql = "select m.id,m.title,m.content,u.name as user,m.time from message m,users u where m.messageuser = u.id";
List<Map<String, String>>list = new DBHelper().queryObjects(sql, null, new String[]{"id","title","content","user","time"});
if(list!=null && list.size()>0){
return JSONArray.fromObject(list).toString();
}else return "error:未获取到留言信息";
}

private String findRoom(HttpServletRequest request,
HttpServletResponse response) {
String id = request.getParameter("id")==null?"":request.getParameter("id");
if(id.equals("")) return "error:ID不能为空!";
String sql = "select * from rooms where id = ?";
String params[]={id};
String fields[]={"id","roomno","type","price","isempty","des","pic"};
Map<String, String> map = new DBHelper().queryObject(sql, params, fields);
if(map!=null && !map.isEmpty()){
if(map.containsKey("pic") &&( map.get("pic")==null || map.get("pic").equals(""))){
map.put("pic", "");
}else{
map.put("pic",request.getRequestURL().toString().split("SLH")[0]+"SLH"+"/"+ImageUtil.PATH+"/"+map.get("pic"));
}
return JSONObject.fromObject(map).toString();
}else
return "error:房间信息未查到!";
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	}
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){


项目链接:
https://javayms.github.io?id=161122542008200sf
https://javayms.pages.dev?id=161122542008200sf