基于javaweb+mysql的jsp+servlet医院挂号预约管理系统(管理员、用户)(java+jsp+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员:登录、管理员、医生、病人、预约挂号、科室管理
普通用户:注册、登录、预约挂号、挂号查询
普通用户(前台)
管理员(后台)
技术框架
CSS JavaScript JSP Servlet JDBC MySQL
基于javaweb+mysql的JSP+Servlet医院挂号预约管理系统(管理员、用户)(java+jsp+servlet+mysql)
public class AdminServlet extends HttpServlet {
private AdminService adminService = new AdminServiceImpl();
public AdminServlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String method = request.getParameter("method");
if (method.equals("add")) {
// 添加用户
add(request, response);
} else if (method.equals("adminLogin")) {
// 管理员登录
adminLogin(request, response);
} else if (method.equals("showList")) {
// 显示管理员列表
showList(request, response);
if (!isReg) {// 没有预约时
b = doctorService.delete(Integer.valueOf(docId));
}
} else {
// 都为空的时候
JOptionPane.showMessageDialog(null, "您还没有选择删除的人");// 跳出去
showList(request, response);
return;
}
}
if (!b) {
JOptionPane.showMessageDialog(null, "不能删除有预约的医生信息");
request.setAttribute("error", "删除医生失败");
}
showList(request, response);
}
public void init() throws ServletException {
// Put your code here
}
}
Office office = officeService.get(doc.getOffId());
request.setAttribute("doc", doc);
request.setAttribute("off", office);
request.getRequestDispatcher("/admin/regShowDoctor.jsp").forward(
request, response);
} else {
request.getRequestDispatcher("/admin/doctorList.jsp").forward(
request, response);
}
}
// 添加,初始化列表框
public void gotoAdd(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 查询 科室,得到科室名,初始化列表框
List<Office> offList = officeService.getList(null, null); // ???
// 保存值,跳转到页面
request.setAttribute("offList", offList);
request.getRequestDispatcher("/admin/addDoctor.jsp").forward(request,
response);
}
// 添加
public void add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String filename = "";
SmartUpload su = new SmartUpload();
// 初始化SmartUpload对象
su.initialize(this.getServletConfig(), request, response);
com.jspsmart.upload.File file = null;
// 允许上传类型
String allowed = "gif,jpg,doc,rar";
// 不许上传类型
String denied = "jsp,asp,php,aspx,html,htm,exe,bat";
com.jspsmart.upload.Request req = null;
// 设置上传文件大小
int file_size = 2 * 1024 * 1024;
String exceptionMsg = null;
int i = 0;
try {
// 定义允许上传文件类型
su.setAllowedFilesList(allowed);
// 不允许上传文件类型
su.setDeniedFilesList(denied);
// 单个文件最大限制
su.setMaxFileSize(file_size);
su.setCharset("UTF-8");
// 执行上传
su.upload();
// 得到单个上传文件的信息
file = su.getFiles().getFile(0);
String filepath = null;
if (!file.isMissing()) {
// 得到admin,初始化界面,
String adminId = request.getParameter("adminId");
Admin admin = adminService.getAdmin(Integer.valueOf(adminId));
request.setAttribute("admin", admin);
request.getRequestDispatcher("/admin/updateAdmin.jsp").forward(request,
response);
}
// 根据管理员id删除
public void delete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 删除单个传来的值
String adminId = request.getParameter("adminId");
// 删除多个传来的值
String str = request.getParameter("adminIdArr");// 得到id的字符串,然后分割成数组
boolean b = false;
if (str != null && !str.trim().equals("")) {
String arrId[] = str.split(","); // 将字符串分割成数组,得到所有复选框的value,即管理员id
for (int i = 0; i < arrId.length; i++) {
System.out.println(arrId[i]);
b = adminService.delete(Integer.valueOf(arrId[i]));
}
} else {
if (adminId != null) {
b = adminService.delete(Integer.valueOf(adminId));
} else {
// 都为空的时候
JOptionPane.showMessageDialog(null, "您还没有选择删除的人");// 跳出去
showList(request, response);
return;
}
}
if (!b) {
request.setAttribute("errDelete", "删除管理员失败");
}
showList(request, response);
}
}
// 判断是否重名
public boolean isReName(String adminName, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
boolean reName = false;
// 判断不能重名
List<Admin> list = adminService.getAdminList(null, null); // 得到列表,查询所有的
if (list != null) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getAdminName().equals(adminName)) {
reName = true;
break;
}
}
}
return reName;
}
public void add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 添加管理员
String adminName = request.getParameter("adminName");
String password = request.getParameter("password");
String rePassword = request.getParameter("rePassword");
if (adminName == null || adminName.trim().equals("")) {
request.setAttribute("error", "用户名不能为空");
request.getRequestDispatcher("/admin/admin_add.jsp").forward(
request, response);
return;
}
if (password == null || password.trim().equals("")) {
request.setAttribute("error", "密码不能为空");
request.getRequestDispatcher("/admin/admin_add.jsp").forward(
request, response);
return;
}
if (rePassword == null || rePassword.trim().equals("")) {
request.setAttribute("error", "确认密码不能为空");
request.getRequestDispatcher("/admin/admin_add.jsp").forward(
request, response);
return;
}
if (!rePassword.equals(password)) {
request.setAttribute("error", "两次密码不一致");
request.getRequestDispatcher("/admin/admin_add.jsp").forward(
request, response);
request.getRequestDispatcher("/admin/admin_add.jsp").forward(
request, response);
return;
}
if (!rePassword.equals(password)) {
request.setAttribute("error", "两次密码不一致");
request.getRequestDispatcher("/admin/admin_add.jsp").forward(
request, response);
return;
}
// 开始往数据库里插入数据--添加管理员
boolean reName = isReName(adminName, request, response); // 判断不能重名
Admin admin = new Admin(adminName, password);
boolean b = false;
if (!reName) {
// 如果没有重名,插入数据库
b = adminService.addAdmin(admin);
} else {
request.setAttribute("error", "已存在此用户");
request.getRequestDispatcher("/admin/admin_add.jsp").forward(
request, response);
return;
}
if (b) {
// 添加成功
// JOptionPane.showMessageDialog(null, "注册管理员成功");
showList(request, response);
} else {
// 添加失败,返回到添加页面
request.setAttribute("error", "添加管理员失败");
request.getRequestDispatcher("/admin/admin_add.jsp").forward(
request, response);
}
}
// 显示管理员列表
public void showList(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String checkName = request.getParameter("checkName"); // 得到名字,根据姓名查找时用
// 分页
PageData pageData = new PageData();
// 得到当前页
String currentPage = request.getParameter("currentPage");
if (currentPage != null) {
pageData.setCurrentPage(Integer.valueOf(currentPage));
dto.setDocTime(doc.getDocTime());
dto.setMoney(doc.getMoney());
dto.setSumCount(doc.getSumCount());
dto.setLessCount(doc.getLessCount());
request.setAttribute("doctorDto", dto);
request.getRequestDispatcher("/admin/updateDoctor.jsp").forward(
request, response);
}
public void modify(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String docId = request.getParameter("docId");// 根据这个修改医生,
Doctor doctor = doctorService.get(Integer.valueOf(docId));
System.out.println(docId);
// 得到值,注意:页面不能有上传文件时所需要的enctype="multipart/form-data",否则得不到页面的值
String docName = request.getParameter("docName");
int money = Integer.valueOf(request.getParameter("money"));
String docTime = request.getParameter("docTime"); // 需要将其转化成sql里面的日期
int sumCount = Integer.valueOf(request.getParameter("sumCount"));
int offId = Integer.valueOf(request.getParameter("offId"));// 得到的就是offId
Date timeDate = DateUtil.getBirthDate(docTime);
// 更新得到的值
doctor.setDocName(docName);
doctor.setMoney(money);
doctor.setDocTime(timeDate);
doctor.setSumCount(sumCount);
doctor.setOffId(offId);
// 插入数据库
boolean b = doctorService.modify(doctor);
if (b) {
// 成功
// 跳转到列表,要更新
System.out.println("成功");
showList(request, response);
} else {
// 插入失败
System.out.println("失败");
request.setAttribute("error", "修改医生信息失败");
request.getRequestDispatcher("/admin/updateDoctor.jsp").forward(
request, response);
}
}
// 删除
public void delete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 删除单个
String docId = request.getParameter("docId");
// 单个删除
String regId = request.getParameter("regId");
// 多个删除
String strId = request.getParameter("strId");
boolean b = false;
if (strId != null && !strId.trim().equals("")) {
String arrId[] = strId.split(","); // 将字符串分割成数组,得到所有复选框的value,即管理员id
for (int i = 0; i < arrId.length; i++) {
b = registerService.delete(Integer.valueOf(arrId[i]));
}
} else {
if (regId != null) {
b = registerService.delete(Integer.valueOf(regId));
} else {
// 都为空的时候
JOptionPane.showMessageDialog(null, "您还没有选择删除的人");// 跳出去
showList(request, response);
return;
}
}
if (!b) {
request.setAttribute("error", "删除失败");
}
showList(request, response);
}
public void init() throws ServletException {
}
}
public class RegisterServlet extends HttpServlet {
private RegisterService registerService = new RegisterServiceImp();
private PatientService patientService = new PatientServiceImp();
private DoctorService doctorService = new DoctorServiceImp();
private OfficeService officeService = new OfficeServiceImp();
public RegisterServlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
// 得到值
String method = request.getParameter("method");
if (method.equals("selectRegister")) {
// 前台查询挂号信息
selectRegister(request, response);
} else if (method.equals("showList")) {
// 显示诊室列表
showList(request, response);
} else if (method.equals("add")) {
// 前台挂号
add(request, response);
} else if (method.equals("delete")) {
} else if (method.equals("add")) {
// 前台挂号
add(request, response);
} else if (method.equals("delete")) {
delete(request, response);
} else if (method.equals("addAjax")) {
addAjax(request, response);
}
}
// 前台查询挂号
public void selectRegister(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 得到用户名,密码
String pName = request.getParameter("pName"); // 得到输入的用户名
String password = request.getParameter("password");
if (pName == null || pName.trim().equals("")) {
request.setAttribute("error", "用户名不能为空");
request.getRequestDispatcher("/guhao_select.jsp").forward(request,
response);
return;
}
if (password == null || password.trim().equals("")) {
request.setAttribute("error", "密码不能为空");
request.getRequestDispatcher("/guhao_select.jsp").forward(request,
response);
return;
}
// 根据用户名得到病人,得到预约信息
Patient patient = patientService.get(pName);
if (patient != null) {
if (patient.getPassword().equals(password)) {
// 根据病人id得到预约挂号信息
Register register = registerService.getByPId(patient.getpId());
if (register != null) {
// 显示预约信息,得到医生, 科室
Doctor doctor = doctorService.get(register.getDocId());
Office office = officeService.get(doctor.getOffId());
request.setAttribute("p", patient);
request.setAttribute("doc", doctor);
if (rowsCount % pageData.getPageRows() == 0) {
pageCount = rowsCount / pageData.getPageRows();
} else {
pageCount = rowsCount / pageData.getPageRows() + 1;
}
pageData.setPageCount(pageCount);
// 先查询数据库
List<Patient> pList = patientService.getList(checkName, pageData);// 查询所有的
// 查看是否有预约,有预约姓名显示红色,没有预约显示黑色,删除时就只能删除黑色的
for (Patient p : pList) {
boolean isReg = isHasReg(p.getpId(), request, response);
if (isReg) {
p.setColor("red");
} else {
p.setColor("black");
}
}
// 跳到页面,并将值传过去
request.setAttribute("pList", pList);
request.setAttribute("page", pageData); // 将page传过去
request.setAttribute("checkName", checkName);// 不让名字清空
// 预约挂号中链接病人姓名得到信息
String regPId = request.getParameter("regPId");
if (regPId != null) {
// 显示单条病人信息
Patient patient = patientService.get(Integer.valueOf(regPId));
request.setAttribute("patient", patient);
request.getRequestDispatcher("/admin/regShowPatient.jsp").forward(
request, response);
} else {
request.getRequestDispatcher("/admin/patientList.jsp").forward(
request, response);
}
}
// 添加
public void add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 得到值
String name = request.getParameter("name");
String password = request.getParameter("password");
String rePassword = request.getParameter("rePassword");
String relname = request.getParameter("relname");
String sex = request.getParameter("sex");
request, response);
}
}
// 添加
public void add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 得到值
String name = request.getParameter("name");
String password = request.getParameter("password");
String rePassword = request.getParameter("rePassword");
String relname = request.getParameter("relname");
String sex = request.getParameter("sex");
String tel = request.getParameter("tel");
String card = request.getParameter("card");
// 判断在前台页面判断
if (name == null || name.trim().equals("")) {
request.setAttribute("error", "用户名不能为空");
request.getRequestDispatcher("/patient_regist.jsp").forward(
request, response);
return;
}
if (password == null || password.trim().equals("")) {
request.setAttribute("error", "密码不能为空");
request.getRequestDispatcher("/patient_regist.jsp").forward(
request, response);
return;
}
if (rePassword == null || rePassword.trim().equals("")) {
request.setAttribute("error", "确认密码不能为空");
request.getRequestDispatcher("/patient_regist.jsp").forward(
request, response);
return;
}
if (!rePassword.equals(password)) {
request.setAttribute("error", "两次密码不一致");
request.getRequestDispatcher("/patient_regist.jsp").forward(
request, response);
return;
}
if (relname == null || relname.trim().equals("")) {
request.setAttribute("error", "真实姓名不能为空");
private DoctorService doctorService = new DoctorServiceImp();
private OfficeService officeService = new OfficeServiceImp();
private RegisterService registerService = new RegisterServiceImp();
public DoctorServlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code heref
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// System.out.println("uiuiuiui");
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
// 得到值
String method = request.getParameter("method");
if (method.equals("frontShowList")) {
// 前台挂号时需要
frontShowList(request, response);
} else if (method.equals("selectDocList")) {
// 前台查询医生列表
selectDocList(request, response);
} else if (method.equals("showList")) {
// 显示诊室列表
showList(request, response);
} else if (method.equals("gotoAdd")) {
// 添加时先初始化下拉列表框
gotoAdd(request, response);
} else {
pageCount = rowsCount / pageData.getPageRows() + 1;
}
pageData.setPageCount(pageCount);
// 先查询数据库
List<Office> offList = officeService.getList(checkName, pageData); // 得到所有的
// 查看是否有医生,有医生显示红色,
for (Office off : offList) {
boolean isDoc = isHasDoc(off.getOffId(), request, response);
if (isDoc) {
off.setColor("red");
} else {
off.setColor("black");
}
}
// 跳到页面,并将值传过去
request.setAttribute("offList", offList);
request.setAttribute("page", pageData); // 将page传过去
request.setAttribute("checkName", checkName);// 不让名字清空
// 跳到后台
request.getRequestDispatcher("/admin/officeList.jsp").forward(request,
response);
}
// 添加
public void add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String offId = request.getParameter("offId");
String offName = request.getParameter("offName");
// 得到值
System.out.println(offId);
System.out.println(offName);
// 判断在前台页面判断
if (offId == null || offId.trim().equals("")) {
request.setAttribute("error", "科室编号不能为空");
request.getRequestDispatcher("/admin/addOffice.jsp").forward(
request, response);
return;
}
if (offName == null || offName.trim().equals("")) {
request.setAttribute("error", "科室名称不能为空");
request.getRequestDispatcher("/admin/addOffice.jsp").forward(
request, response);
return;
}
// 插入数据库
System.out.println("失败");
request.setAttribute("error", "修改医生信息失败");
request.getRequestDispatcher("/admin/updateDoctor.jsp").forward(
request, response);
}
}
// 删除
public void delete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 删除单个
String docId = request.getParameter("docId");
// 多个删除
String strId = request.getParameter("strId");
boolean b = false;
boolean isReg = false; // 默认没有预约
if (strId != null && !strId.trim().equals("")) {
String arrId[] = strId.split(","); // 将字符串分割成数组,得到所有复选框的value,即管理员id
for (int i = 0; i < arrId.length; i++) {
// 删除之前先查询看是否有预约
isReg = isHasReg(Integer.valueOf(arrId[i]), request, response);
if (!isReg) {// 没有预约时
b = doctorService.delete(Integer.valueOf(arrId[i]));
}
}
} else {
if (docId != null) {
isReg = isHasReg(Integer.valueOf(docId), request, response);
if (!isReg) {// 没有预约时
b = doctorService.delete(Integer.valueOf(docId));
}
} else {
// 都为空的时候
JOptionPane.showMessageDialog(null, "您还没有选择删除的人");// 跳出去
showList(request, response);
return;
}
}
if (!b) {
JOptionPane.showMessageDialog(null, "不能删除有预约的医生信息");
request.setAttribute("error", "删除医生失败");
}
showList(request, response);
}
request.setAttribute("error", "科室编号不能为空");
request.getRequestDispatcher("/admin/addOffice.jsp").forward(
request, response);
return;
}
if (offName == null || offName.trim().equals("")) {
request.setAttribute("error", "科室名称不能为空");
request.getRequestDispatcher("/admin/addOffice.jsp").forward(
request, response);
return;
}
// 插入数据库
Office office = new Office(Integer.valueOf(offId), offName);
boolean b = officeService.add(office);
if (b) {
// 成功
// 跳转到列表,要更新
showList(request, response);
} else {
// 插入失败
request.setAttribute("error", "添加失败");
request.getRequestDispatcher("admin/addOffice.jsp").forward(
request, response);
}
}
// 修改
public void gotoModify(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 得到页面的offId,查询数据库,得到对象,初始化页面
String offId = request.getParameter("offId");
// System.out.println(list.size());
Office office = officeService.get(Integer.valueOf(offId));
// 保存值,传到页面
request.setAttribute("office", office);
request.getRequestDispatcher("admin/updateOffice.jsp").forward(request,
response);
}
public void modify(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 得到页面值
int oldOffId = Integer.valueOf(request.getParameter("oldOffId"));// 旧的id
int newOffId = Integer.valueOf(request.getParameter("offId"));
String offName = request.getParameter("offName");
}
pageData.setPageCount(pageCount);
// 先查询数据库,得到医生列表
List<Doctor> docList = doctorService.getList(null, pageData);// 查询所有记
// 查询医生,还要查询科室,得到科室名
List<DoctorDto> docDtoList = new ArrayList<DoctorDto>();
DoctorDto dto = null;
for (Doctor doc : docList) {
// 根据doc.getOffId()得到科室
dto = new DoctorDto(); // 必须在里面创建
Office office = officeService.get(doc.getOffId());// 得到第一条记录
dto.setDocId(doc.getDocId());
dto.setDocName(doc.getDocName());
dto.setOffName(office.getOffName());
dto.setDocImg(doc.getDocImg());
dto.setDocStatus(doc.getDocStatus());
dto.setDocTime(doc.getDocTime());
dto.setMoney(doc.getMoney());
dto.setSumCount(doc.getSumCount());
dto.setLessCount(doc.getLessCount());
docDtoList.add(dto);
}
// 跳到页面,并将值传过去
request.setAttribute("docDtoList", docDtoList);
request.setAttribute("page", pageData); // 将page传过去
request.getRequestDispatcher("/selectDoctorList.jsp").forward(request,
response);
}
// 显示医生列表
public void showList(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 模糊查询
String checkName = request.getParameter("checkName"); // 得到名字,根据姓名查找时用
// 分页
PageData pageData = new PageData();
// 得到当前页
String currentPage = request.getParameter("currentPage");
if (currentPage != null) {
pageData.setCurrentPage(Integer.valueOf(currentPage));
}
// 得到每页行数
String pageRows = request.getParameter("pageRows");
if (pageRows != null) {
pageData.setPageRows(Integer.valueOf(pageRows));
}
// 得到总行数
int rowsCount = doctorService.getRowsCount(checkName);
pageData.setRowsCount(rowsCount);
// 计算总页数