IDEA+Java+Servlet+JSP+Mysql实现Web停车场管理系统建议收藏
Posted 水坚石青
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA+Java+Servlet+JSP+Mysql实现Web停车场管理系统建议收藏相关的知识,希望对你有一定的参考价值。
目录
JavaWeb系统系列实现
Java+Springboot+Mybatis+Bootstrap+Maven实现网上商城系统
一、系统介绍
该系统包含数据库,论文,任务书,开题报告,请在下载源码中下载!!!
走过路过不要错过,点赞加关注的脱单暴富,走上人生巅峰!!!
1.开发环境
开发工具:IDEA2018.2
JDK版本:jdk1.8
mysql版本:8.0.13
2.技术选型
后端:Java+Servlet进行开发。
前端:JSP+html+CSS。
3.系统功能
基于Web停车场管理系统主要用于实现停车场相关信息管理,基本功能包括:系统信息管理模块、车位信息管理模块、IC卡信息管理模块、固定车主停车管理模块、临时车辆信息管理模块、系统功能操模块等。本系统结构如下:
(1)系统信息管理模块:角色的增加、删除、修改和查询;用户的增加、删除、修改和查询。
(2)车位信息管理模块:车位信息的增加、删除、修改和查询。
(3)IC卡信息管理模块:IC卡信息的增加、删除、修改和查询。
(4)固定车主停车管理模块:对固定车主的停车信息进行增加、删除、修改和查询
(5)临时车辆信息管理模块:对临时车辆的停车信息进行增加、删除、修改、查询和打印
(6)系统功能操模块:退出登陆、修改密码。
4.数据库
/*
Navicat Premium Data Transfer
Source Server : MySQL
Source Server Type : MySQL
Source Server Version : 80013
Source Host : 127.0.0.1:3306
Source Schema : servlet_parking
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 12/08/2021 20:37:52
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for card
-- ----------------------------
DROP TABLE IF EXISTS `card`;
CREATE TABLE `card` (
`card_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`seat_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`user_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`user_gender` varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`user_addr` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`car_num` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`card_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of card
-- ----------------------------
INSERT INTO `card` VALUES ('20150521190631', '20150521182303', '李小龙', '男', '香语区A栋3-105', '川A12345');
INSERT INTO `card` VALUES ('20150521192828', '20150521182304', '黎明', '男', '香语区A栋3-106', '川A12346');
INSERT INTO `card` VALUES ('20150521192854', '20150521182305', '王林', '女', '香语区A栋3-107', '川A12348');
INSERT INTO `card` VALUES ('20150521192915', '20150521182306', '龙飞', '男', '香语区A栋3-108', '川A12349');
-- ----------------------------
-- Table structure for fixed
-- ----------------------------
DROP TABLE IF EXISTS `fixed`;
CREATE TABLE `fixed` (
`fixed_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`card_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`entry_date` date NOT NULL,
`entry_time` time(0) NOT NULL,
`out_date` date NULL DEFAULT NULL,
`out_time` time(0) NULL DEFAULT NULL,
PRIMARY KEY (`fixed_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of fixed
-- ----------------------------
INSERT INTO `fixed` VALUES ('20150522104145', '20150521192915', '2015-05-22', '10:41:45', '2015-09-25', '10:23:34');
INSERT INTO `fixed` VALUES ('20150925102400', '20150521192828', '2015-09-25', '10:24:00', '2015-09-25', '10:24:07');
INSERT INTO `fixed` VALUES ('20150925104659', '20150521192854', '2015-09-25', '10:46:59', '2015-09-25', '17:29:04');
INSERT INTO `fixed` VALUES ('20150925180626', '20150521190631', '2015-09-25', '18:06:26', '2015-12-01', '19:04:56');
INSERT INTO `fixed` VALUES ('20210812203257', '20150521190631', '2021-08-12', '20:32:57', '2021-08-12', '20:33:30');
INSERT INTO `fixed` VALUES ('20210812203323', '20150521190631', '2021-08-12', '20:33:23', '2021-08-12', '20:33:38');
-- ----------------------------
-- Table structure for role
-- ----------------------------
DROP TABLE IF EXISTS `role`;
CREATE TABLE `role` (
`role_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`role_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`role_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of role
-- ----------------------------
INSERT INTO `role` VALUES ('r001', '超级管理员');
INSERT INTO `role` VALUES ('r002', '普通管理员');
-- ----------------------------
-- Table structure for seat
-- ----------------------------
DROP TABLE IF EXISTS `seat`;
CREATE TABLE `seat` (
`seat_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`seat_num` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`seat_section` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`seat_state` int(11) NOT NULL,
`seat_tag` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`seat_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of seat
-- ----------------------------
INSERT INTO `seat` VALUES ('20150521182303', 'A1001', 'A区', 1, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182304', 'A1002', 'A区', 1, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182305', 'A1003', 'A区', 1, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182306', 'A1004', 'A区', 1, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182307', 'A1005', 'A区', 1, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182308', 'A1006', 'A区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182309', 'A1007', 'A区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182310', 'A1008', 'A区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182311', 'VIP1001', 'B区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182312', 'VIP1002', 'B区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182313', 'VIP1003', 'B区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182314', 'VIP1004', 'B区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182315', 'VIP1005', 'B区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182316', 'VIP1007', 'B区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182318', 'VIP10010', 'B区', 0, '固定车主车位');
INSERT INTO `seat` VALUES ('20150521182319', 'VIP10012', 'B区', 0, '固定车主车位');
-- ----------------------------
-- Table structure for temp
-- ----------------------------
DROP TABLE IF EXISTS `temp`;
CREATE TABLE `temp` (
`temp_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`card_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`car_num` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`entry_date` date NOT NULL,
`entry_time` time(0) NOT NULL,
`out_date` date NULL DEFAULT NULL,
`out_time` time(0) NULL DEFAULT NULL,
`temp_money` float NULL DEFAULT NULL,
PRIMARY KEY (`temp_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of temp
-- ----------------------------
INSERT INTO `temp` VALUES ('20150925173007', '川B23333', '川B23333', '2015-09-25', '17:30:07', '2015-11-28', '21:29:26', 20);
INSERT INTO `temp` VALUES ('20150925203021', '川B23333', '川B23333', '2015-09-25', '20:30:21', '2015-11-28', '21:29:26', 15);
INSERT INTO `temp` VALUES ('20151201190239', '川B11111', '川B11111', '2015-12-01', '19:02:39', '2015-12-01', '19:04:24', 3);
INSERT INTO `temp` VALUES ('20151201190418', '川F22222', '川F22222', '2015-12-01', '19:04:18', '2015-12-01', '19:04:28', 3);
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`user_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`role_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`user_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`real_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`user_pwd` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`user_phone` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`user_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('admin_01', 'r002', 'Lulu', '鲁露', '123456', '13900000002');
INSERT INTO `user` VALUES ('admin_02', 'r002', 'Ilin', '依琳', '123456', '13900000003');
INSERT INTO `user` VALUES ('SAdmin', 'r001', 'Jimi', '吉米', '123456', '13900000001');
-- ----------------------------
-- View structure for v_card
-- ----------------------------
DROP VIEW IF EXISTS `v_card`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_card` AS select `card`.`card_id` AS `card_id`,`card`.`seat_id` AS `seat_id`,`card`.`user_name` AS `user_name`,`card`.`user_gender` AS `user_gender`,`card`.`user_addr` AS `user_addr`,`card`.`car_num` AS `car_num`,`seat`.`seat_num` AS `seat_num` from (`card` join `seat` on((`card`.`seat_id` = `seat`.`seat_id`)));
-- ----------------------------
-- View structure for v_fixed
-- ----------------------------
DROP VIEW IF EXISTS `v_fixed`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_fixed` AS select `fixed`.`fixed_id` AS `fixed_id`,`fixed`.`card_id` AS `card_id`,`fixed`.`entry_date` AS `entry_date`,`fixed`.`entry_time` AS `entry_time`,`fixed`.`out_date` AS `out_date`,`fixed`.`out_time` AS `out_time`,`card`.`car_num` AS `car_num`,`card`.`user_name` AS `user_name` from (`fixed` join `card` on((`fixed`.`card_id` = `card`.`card_id`)));
-- ----------------------------
-- View structure for v_user
-- ----------------------------
DROP VIEW IF EXISTS `v_user`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_user` AS select `user`.`user_id` AS `user_id`,`user`.`role_id` AS `role_id`,`user`.`user_name` AS `user_name`,`user`.`real_name` AS `real_name`,`user`.`user_pwd` AS `user_pwd`,`user`.`user_phone` AS `user_phone`,`role`.`role_name` AS `role_name` from (`user` join `role` on((`user`.`role_id` = `role`.`role_id`)));
SET FOREIGN_KEY_CHECKS = 1;
5.工程截图
二、系统展示
1.登录界面
2.主页面
3.系统信息管理-添加角色信息
4.系统信息管理-管理角色信息
5.系统信息管理-添加用户信息
6.系统信息管理-管理用户信息
7.车位信息管理-添加车位信息
8.车位信息管理-管理车位信息
9.IC卡信息管理-添加IC卡类型
10.IC卡信息管理-管理IC卡类型
11.固定车主停车管理-出入场设置
12.固定车主停车管理-停车信息管理
13.临时车辆停车管理-车主入场信息
14.临时车辆停车管理-车主出场信息
15.系统功能操作-修改密码
三、部分代码
CardHandle
package ServletHandle;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
public class CardHandle extends HttpServlet {
HttpServletRequest request;
HttpServletResponse response;
DAL.Card card = new DAL.Card();
//通过表单get方式传值 将进入doGet函数(method="get")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.response = response;
this.request = request;
int handleType = Integer.parseInt(request.getParameter("type").toString());
switch (handleType) {
case 1://类型1代表删除表中的数据
deleteEntity();
break;
case 4://类型4代表获取表中信息
getEntity();
break;
case 5://类型5代表根据查询条件获取表中信息
getEntityByWhere();
break;
default:
break;
}
}
//通过表单post方式传值 将进入doPost函数(method="post")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.request = request;
this.response = response;
int handleType = Integer.parseInt(request.getParameter("type").toString());//将前台页面传过来的type类型转化成整型
switch (handleType) {
case 2://类型2代表更新表中的数据
updateEntity();
break;
case 3://类型3代表向表中添加数据
insertEntity();
break;
default:
break;
}
}
//删除数据操作
private void deleteEntity() throws IOException {
String card_id = request.getParameter("card_id");//获取前台通过get方式传过来的JId
card.deleteEntity(card_id);//执行删除操作
response.sendRedirect("/Parking/CardHandle?type=4");//删除成功后跳转至管理页面
}
//更新数据操作
private void updateEntity() throws UnsupportedEncodingException {
String card_id = new String(request.getParameter("card_id").getBytes("ISO8859_1"), "UTF-8");
String seat_id = new String(request.getParameter("seat_id").getBytes("ISO8859_1"), "UTF-8");
String user_name = new String(request.getParameter("user_name").getBytes("ISO8859_1"), "UTF-8");
String user_gender = new String(request.getParameter("user_gender").getBytes("ISO8859_1"), "UTF-8");
String user_addr = new String(request.getParameter("user_addr").getBytes("ISO8859_1"), "UTF-8");
String car_num = new String(request.getParameter("car_num").getBytes("ISO8859_1"), "UTF-8");
if (card.updateEntity(card_id, seat_id, user_name, user_gender, user_addr, car_num) == 1) {
try {
response.sendRedirect("/Parking/CardHandle?type=4");//成功更新数据后跳转至CardMsg.jsp页面
} catch (IOException e) {
e.printStackTrace();//异常处理
}
}
}
//插入数据操作
private void insertEntity() throws UnsupportedEncodingException, IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String card_id = dateFormat.format(new Date());
String seat_id = new String(request.getParameter("seat_id").getBytes("ISO8859_1"), "UTF-8");
String user_name = new String(request.getParameter("user_name").getBytes("ISO8859_1"), "UTF-8");
String user_gender = new String(request.getParameter("user_gender").getBytes("ISO8859_1"), "UTF-8");
String user_addr = new String(request.getParameter("user_addr").getBytes("ISO8859_1"), "UTF-8");
String car_num = new String(request.getParameter("car_num").getBytes("ISO8859_1"), "UTF-8");
if (!card.checkExist(card_id)) {
if (card.insertEntity(card_id, seat_id, user_name, user_gender, user_addr, car_num) == 1) {
out.write("<script>alert('数据添加成功!'); location.href = '/Parking/CardHandle?type=4';</script>");
} else {
out.write("<script>alert('数据添失败!'); location.href = '/Parking/CardHandle?type=4';</script>");
}
} else {
out.write("<script>alert('主键重复,数据添加失败!'); location.href = '/Parking/CardHandle?type=4';</script>");
}
}
//获取对象所有数据列表
private void getEntity() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page").toString());//获取跳转的页面号
int totalPage = Integer.parseInt(card.getPageCount().toString());//获取分页总数
List<Object> list = card.getEntity(page);//获取数据列表
request.setAttribute("list", list);//将数据存放到request对象中,用于转发给前台页面使用
request.setAttribute("totalPage", totalPage);//将totalPage存放到request对象中,用于转发给前台页面使用
request.getRequestDispatcher("/Admin/CardMsg.jsp").forward(request, response);//请求转发
}
//根据查询条件获取对象所有数据列表
private void getEntityByWhere() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String condition = request.getParameter("condition");//获取查询字段的名称
//String value=new String(request.getParameter("value").getBytes("ISO8859_1"),"UTF-8");//获取查询的值
String value = request.getParameter("value");
String where = condition + "=\\"" + value + "\\"";//拼接查询字符串
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));//获取要跳转的页面号
int wherePage = Integer.parseInt(card.getPageCountByWhere(where).toString());//获取查询后的分页总数
List<Object> list = card.getEntityByWhere(where, page);//获取查询后的数据列表
request.setAttribute("list", list);//将数据存放到request对象中,用于转发给前台页面使用
request.setAttribute("wherePage", wherePage);
request.setAttribute("condition", condition);
request.setAttribute("value", value);
request.getRequestDispatcher("/Admin/CardMsg.jsp").forward(request, response);
}
}
FixedHandle
package ServletHandle;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
public class FixedHandle extends HttpServlet {
HttpServletRequest request;
HttpServletResponse response;
DAL.Fixed fixed = new DAL.Fixed();
//通过表单get方式传值 将进入doGet函数(method="get")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.response = response;
this.request = request;
int handleType = Integer.parseInt(request.getParameter("type").toString());
switch (handleType) {
case 1://类型1代表删除表中的数据
deleteEntity();
break;
case 4://类型4代表获取表中信息
getEntity();
break;
case 5://类型5代表根据查询条件获取表中信息
getEntityByWhere();
break;
case 6://类型6代表管理员获取未出场车辆
getNoOut();
break;
case 10://类型10代表更新车辆出场
setOut();
break;
default:
break;
}
}
//通过表单post方式传值 将进入doPost函数(method="post")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.request = request;
this.response = response;
int handleType = Integer.parseInt(request.getParameter("type").toString());//将前台页面传过来的type类型转化成整型
switch (handleType) {
case 2://类型2代表更新表中的数据
updateEntity();
break;
case 3://类型3代表向表中添加数据
insertEntity();
break;
default:
break;
}
}
//删除数据操作
private void deleteEntity() throws IOException {
String fixed_id = request.getParameter("fixed_id");//获取前台通过get方式传过来的JId
fixed.deleteEntity(fixed_id);//执行删除操作
response.sendRedirect("/Parking/FixedHandle?type=4");//删除成功后跳转至管理页面
}
//车辆出场更新操作
private void setOut() throws IOException {
String fixed_id = new String(request.getParameter("fixed_id").getBytes("ISO8859_1"), "UTF-8");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String out_date = dateFormat.format(new Date());
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
String out_time = timeFormat.format(new Date());
if (fixed.setOut(fixed_id, out_date, out_time) == 1) {
response.sendRedirect("/Parking/FixedHandle?type=6");
}
}
//更新数据操作
private void updateEntity() throws UnsupportedEncodingException {
String fixed_id = new String(request.getParameter("fixed_id").getBytes("ISO8859_1"), "UTF-8");
String card_id = new String(request.getParameter("card_id").getBytes("ISO8859_1"), "UTF-8");
String entry_date = new String(request.getParameter("entry_date").getBytes("ISO8859_1"), "UTF-8");
String entry_time = new String(request.getParameter("entry_time").getBytes("ISO8859_1"), "UTF-8");
String out_date = new String(request.getParameter("out_date").getBytes("ISO8859_1"), "UTF-8");
String out_time = new String(request.getParameter("out_time").getBytes("ISO8859_1"), "UTF-8");
if (fixed.updateEntity(fixed_id, card_id, entry_date, entry_time, out_date, out_time) == 1) {
try {
response.sendRedirect("/Parking/FixedHandle?type=4");//成功更新数据后跳转至FixedMsg.jsp页面
} catch (IOException e) {
e.printStackTrace();//异常处理
}
}
}
//插入数据操作
private void insertEntity() throws UnsupportedEncodingException, IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String fixed_id = dateFormat.format(new Date());
String card_id = new String(request.getParameter("card_id").getBytes("ISO8859_1"), "UTF-8");
SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd");
String entry_date = dFormat.format(new Date());
SimpleDateFormat tFormat = new SimpleDateFormat("HH:mm:ss");
String entry_time = tFormat.format(new Date());
String out_date = "1111-11-11";
String out_time = "11:11:11";
if (!fixed.checkExist(fixed_id)) {
if (fixed.insertEntity(fixed_id, card_id, entry_date, entry_time, out_date, out_time) == 1) {
out.write("<script>alert('数据添加成功!'); location.href = '/Parking/FixedHandle?type=6';</script>");
} else {
out.write("<script>alert('数据添失败!'); location.href = '/Parking/FixedHandle?type=6';</script>");
}
} else {
out.write("<script>alert('主键重复,数据添加失败!'); location.href = '/Parking/FixedHandle?type=4';</script>");
}
}
//获取对象所有数据列表
private void getEntity() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page").toString());//获取跳转的页面号
int totalPage = Integer.parseInt(fixed.getPageCount().toString());//获取分页总数
List<Object> list = fixed.getEntity(page);//获取数据列表
request.setAttribute("list", list);//将数据存放到request对象中,用于转发给前台页面使用
request.setAttribute("totalPage", totalPage);//将totalPage存放到request对象中,用于转发给前台页面使用
request.getRequestDispatcher("/Admin/FixedMsg.jsp").forward(request, response);//请求转发
}
//获取未出场的车辆
private void getNoOut() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page").toString());//获取跳转的页面号
int totalPage = Integer.parseInt(fixed.getPageCount().toString());//获取分页总数
List<Object> list = fixed.getNoOut(page);//获取数据列表
request.setAttribute("list", list);//将数据存放到request对象中,用于转发给前台页面使用
request.setAttribute("totalPage", totalPage);//将totalPage存放到request对象中,用于转发给前台页面使用
request.getRequestDispatcher("/Admin/FixedOut.jsp").forward(request, response);//请求转发
}
//根据查询条件获取对象所有数据列表
private void getEntityByWhere() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String condition = request.getParameter("condition");//获取查询字段的名称
//String value=new String(request.getParameter("value").getBytes("ISO8859_1"),"UTF-8");//获取查询的值
String value = request.getParameter("value");
String where = condition + "=\\"" + value + "\\"";//拼接查询字符串
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));//获取要跳转的页面号
int wherePage = Integer.parseInt(fixed.getPageCountByWhere(where).toString());//获取查询后的分页总数
List<Object> list = fixed.getEntityByWhere(where, page);//获取查询后的数据列表
request.setAttribute("list", list);//将数据存放到request对象中,用于转发给前台页面使用
request.setAttribute("wherePage", wherePage);
request.setAttribute("condition", condition);
request.setAttribute("value", value);
request.getRequestDispatcher("/Admin/FixedMsg.jsp").forward(request, response);
}
}
LoginHandle
package ServletHandle;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class LoginHandle extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");//设置输出编码格式
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession();
String user_id = request.getParameter("user_id");//获取前台url传过来的uName参数
String user_pwd = request.getParameter("user_pwd");//获取前台url传过来的uPwd参数
DAL.Login _login = new DAL.Login();//实例化Login对象,来至DAL包
boolean result = _login.checkLogin(user_id, user_pwd);//检查登陆用户是否合法
if (result)//登陆正确
{
session.setAttribute("user_id", user_id);//将用户userId保存在session对象中全局使用
String user_name = _login.getName(user_id);//获取用户名
session.setAttribute("user_name", user_name);
String role_id = _login.getSysLevel(user_id);
session.setAttribute("role_id", role_id);
request.getRequestDispatcher("/index.jsp").forward(request, response);
} else {//登陆错误
PrintWriter out = response.getWriter();
out.write("<script>alert('用户名或密码错误!');location.href='Login.jsp';</script>");
}
}
}
RoleHandle
package ServletHandle;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
public class RoleHandle extends HttpServlet {
HttpServletRequest request;
HttpServletResponse response;
DAL.Role role = new DAL.Role();
//通过表单get方式传值 将进入doGet函数(method="get")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.response = response;
this.request = request;
int handleType = Integer.parseInt(request.getParameter("type").toString());
switch (handleType) {
case 1://类型1代表删除表中的数据
deleteEntity();
break;
case 4://类型4代表获取表中信息
getEntity();
break;
case 5://类型5代表根据查询条件获取表中信息
getEntityByWhere();
break;
default:
break;
}
}
//通过表单post方式传值 将进入doPost函数(method="post")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.request = request;
this.response = response;
int handleType = Integer.parseInt(request.getParameter("type").toString());//将前台页面传过来的type类型转化成整型
switch (handleType) {
case 2://类型2代表更新表中的数据
updateEntity();
break;
case 3://类型3代表向表中添加数据
insertEntity();
break;
default:
break;
}
}
//删除数据操作
private void deleteEntity() throws IOException {
String role_id = request.getParameter("role_id");//获取前台通过get方式传过来的JId
role.deleteEntity(role_id);//执行删除操作
response.sendRedirect("/Parking/RoleHandle?type=4");//删除成功后跳转至管理页面
}
//更新数据操作
private void updateEntity() throws UnsupportedEncodingException {
String role_id = new String(request.getParameter("role_id").getBytes("ISO8859_1"), "UTF-8");
String role_name = new String(request.getParameter("role_name").getBytes("ISO8859_1"), "UTF-8");
if (role.updateEntity(role_id, role_name) == 1) {
try {
response.sendRedirect("/Parking/RoleHandle?type=4");//成功更新数据后跳转至RoleMsg.jsp页面
} catch (IOException e) {
e.printStackTrace();//异常处理
}
}
}
//插入数据操作
private void insertEntity() throws UnsupportedEncodingException, IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String role_id = new String(request.getParameter("role_id").getBytes("ISO8859_1"), "UTF-8");
String role_name = new String(request.getParameter("role_name").getBytes("ISO8859_1"), "UTF-8");
if (!role.checkExist(role_id)) {
if (role.insertEntity(role_id, role_name) == 1) {
out.write("<script>alert('数据添加成功!'); location.href = '/Parking/RoleHandle?type=4';</script>");
} else {
out.write("<script>alert('数据添失败!'); location.href = '/Parking/RoleHandle?type=4';</script>");
}
} else {
out.write("<script>alert('主键重复,数据添加失败!'); location.href = '/Parking/RoleHandle?type=4';</script>");
}
}
//获取对象所有数据列表
private void getEntity() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page").toString());//获取跳转的页面号
int totalPage = Integer.parseInt(role.getPageCount().toString());//获取分页总数
List<Object> list = role.getEntity(page);//获取数据列表
request.setAttribute("list", list);//将数据存放到request对象中,用于转发给前台页面使用
request.setAttribute("totalPage", totalPage);//将totalPage存放到request对象中,用于转发给前台页面使用
request.getRequestDispatcher("/Admin/RoleMsg.jsp").forward(request, response);//请求转发
}
//根据查询条件获取对象所有数据列表
private void getEntityByWhere() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String condition = request.getParameter("condition");//获取查询字段的名称
System.out.println(condition);
//String value=new String(request.getParameter("value").getBytes("ISO8859_1"),"UTF-8");//获取查询的值
String value = request.getParameter("value");
System.out.println("value " + value);
String where = condition + "=\\"" + value + "\\"";//拼接查询字符串
System.out.println("where " + where);
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));//获取要跳转的页面号
//System.out.println("page +"+page );
int wherePage = Integer.parseInt(role.getPageCountByWhere(where).toString());//获取查询后的分页总数
List<Object> list = role.getEntityByWhere(where, page);//获取查询后的数据列表
System.out.println();
request.setAttribute("list", list);//将数据存放到request对象中,用于转发给前台页面使用
request.setAttribute("wherePage", wherePage);
request.setAttribute("condition", condition);
request.setAttribute("value", value);
request.getRequestDispatcher("/Admin/RoleMsg.jsp").forward(request, response);
}
}
SeatHandle
package ServletHandle;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
public class SeatHandle extends HttpServlet {
HttpServletRequest request;
HttpServletResponse response;
DAL.Seat seat = new DAL.Seat();
//通过表单get方式传值 将进入doGet函数(method="get")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.response = response;
this.request = request;
int handleType = Integer.parseInt(request.getParameter("type").toString());
switch (handleType) {
case 1://类型1代表删除表中的数据
deleteEntity();
break;
case 4://类型4代表获取表中信息
getEntity();
break;
case 5://类型5代表根据查询条件获取表中信息
getEntityByWhere();
break;
default:
break;
}
}
//通过表单post方式传值 将进入doPost函数(method="post")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.request = request;
this.response = response;
int handleType = Integer.parseInt(request.getParameter("type").toString());//将前台页面传过来的type类型转化成整型
switch (handleType) {
case 2://类型2代表更新表中的数据
updateEntity();
break;
case 3://类型3代表向表中添加数据
insertEntity();
break;
default:
break;
}
}
//删除数据操作
private void deleteEntity() throws IOException {
String seat_id = request.getParameter("seat_id");//获取前台通过get方式传过来的JId
seat.deleteEntity(seat_id);//执行删除操作
response.sendRedirect("/Parking/SeatHandle?type=4");//删除成功后跳转至管理页面
}
//更新数据操作
private void updateEntity() throws UnsupportedEncodingException {
String seat_id = new String(request.getParameter("seat_id").getBytes("ISO8859_1"), "UTF-8");
String seat_num = new String(request.getParameter("seat_num").getBytes("ISO8859_1"), "UTF-8");
String seat_section = new String(request.getParameter("seat_section").getBytes("ISO8859_1"), "UTF-8");
String seat_state = new String(request.getParameter("seat_state").getBytes("ISO8859_1"), "UTF-8");
String seat_tag = new String(request.getParameter("seat_tag").getBytes("ISO8859_1"), "UTF-8");
if (seat.updateEntity(seat_id, seat_num, seat_section, seat_state, seat_tag) == 1) {
try {
response.sendRedirect("/Parking/SeatHandle?type=4");//成功更新数据后跳转至SeatMsg.jsp页面
} catch (IOException e) {
e.printStackTrace();//异常处理
}
}
}
//插入数据操作
private void insertEntity() throws UnsupportedEncodingException, IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String seat_id = dateFormat.format(new Date());
String seat_num = new String(request.getParameter("seat_num").getBytes("ISO8859_1"), "UTF-8");
String seat_section = new String(request.getParameter("seat_section").getBytes("ISO8859_1"), "UTF-8");
String seat_state = "0";
String seat_tag = new String(request.getParameter("seat_tag").getBytes("ISO8859_1"), "UTF-8");
if (!seat.checkExist(seat_id)) {
if (seat.insertEntity(seat_id, seat_num, seat_section, seat_state, seat_tag) == 1) {
out.write("<script>alert('数据添加成功!'); location.href = '/Parking/SeatHandle?type=4';</script>");
} else {
out.write("<script>alert('数据添失败!'); location.href = '/Parking/SeatHandle?type=4';</script>");
}
} else {
out.write("<script>alert('主键重复,数据添加失败!'); location.href = '/Parking/SeatHandle?type=4';</script>");
}
}
//获取对象所有数据列表
private void getEntity() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page").toString());//获取跳转的页面号
int totalPage = Integer.parseInt(seat.getPageCount().toString());//获取分页总数
List<Object> list = seat.getEntity(page);//获取数据列表
request.setAttribute("list", list);//将数据存放到request对象中,用于转发给前台页面使用
request.setAttribute("totalPage", totalPage);//将totalPage存放到request对象中,用于转发给前台页面使用
request.getRequestDispatcher("/Admin/SeatMsg.jsp").forward(request, response);//请求转发
}
//根据查询条件获取对象所有数据列表
private void getEntityByWhere() throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String condition = request.getParameter("condition");//获取查询字段的名称
//String value=new String(request.getParameter("value").getBytes("ISO8859_1"),"UTF-8");//获取查询的值
String value = request.getParameter("value");
if (value.equals("闲置")) {
String where = condition + "=0";
System.out.println("where=" + where);
int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));//获取要跳转的页面号
int wherePage = Integer.parseInt(seat.getPageCountByWhere(where).toString());//获取查询后的分页总数
List<Object> list = seat.getEntityByWhere(where, page);//获取查询后的数据列表
request.setAttribute(以上是关于IDEA+Java+Servlet+JSP+Mysql实现Web停车场管理系统建议收藏的主要内容,如果未能解决你的问题,请参考以下文章
IDEA+Java+Servlet+JSP+Mysql实现新闻发布系统
IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统
IDEA+Java+Servlet+JSP+Bootstrap+Mysql实现Web学生成绩管理系统
IDEA+Java+Servlet+JSP+Bootstrap+Mysql实现Web学生成绩管理系统