基于javaweb+mysql的jsp+servlet医院预约挂号系统(java+jdbc+jsp+mysql+ajax)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet医院预约挂号系统(java+jdbc+jsp+mysql+ajax)
一、项目简述
功能: 用户分为患者,医生,管理员,患者可进行注册选择医生 挂号,选择日期,选择号源,医生可进行接诊,管理员可 对用户,医生信息的维护等等功能。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Jdbc+ Servlert + Jsp + css + JavaScript + JQuery + Ajax + Fileupload等等。
case "患者":
PatientDao patientDao=new PatientDao();
List<Patient> patients = patientDao.query("account",account);
if(patients.size()>0){
Patient patient = patients.get(0);
//判断密码是否相同
if(patient.getPassword().equals(password)){
request.getSession().setAttribute("patient",patient);
String url= (String) request.getSession().getAttribute("url");
if(url==null)
url="index.jsp";
request.getSession().setAttribute("message","登录成功!!");
response.sendRedirect(url);
return;
}
}
request.getSession().setAttribute("message","用户名或密码错误!!");
response.sendRedirect("login.jsp");
break;
}
}
}
package com.qst.servlet;
@WebServlet(urlPatterns= "/queryNumSource")
public class QueryNumSource extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
req.getRequestDispatcher("ShowWorkday?did=" + did).forward(req, resp);
}
} else {
req.getSession().setAttribute("message", "号源已被预约!");
req.getRequestDispatcher("ShowWorkday?did=" + did).forward(req, resp);
}
break;
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.qst.servlet;
@WebServlet(urlPatterns= "/modifyPwd")
public class ModifyPwd extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = Util.nullToString(request.getParameter("action"));
String jmm = Util.nullToString(request.getParameter("jmm"));
String xmm = Util.nullToString(request.getParameter("xmm"));
String qdmm = Util.nullToString(request.getParameter("qdmm"));
String message="";
switch (action){
case "doctor":
Doctor doctor = (Doctor)request.getSession().getAttribute("doctor");
if(doctor.getPassword().equals(jmm)){
@WebServlet(urlPatterns = "/RegisterSevlet")
public class RegisterServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("textml;charset=UTF-8");
//获取前台的email
String account=request.getParameter("account");
//判断数据库是否有相同的email
Integer count=new PatientDao().Count("account",account);
String msg = null;
if(count>0){
msg=new String("账号存在");
}
response.getWriter().write(msg);
}
}
package com.qst.servlet.admin;
@WebServlet(urlPatterns = "/patientManage")
public class PatientManage extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
writer.close();
} else {
PrintWriter writer = response.getWriter();
writer.write("false");
writer.flush();
writer.close();
}
}
}
}
package com.qst.servlet.patient;
@WebServlet(urlPatterns ="/OfficeSearch")
public class OfficeSearch extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String office= Util.nullToString(request.getParameter("office"));
int start=Util.nullToZero(request.getParameter("start"));
OfficeDao officeDao=new OfficeDao();
Pages p = new Pages(start , officeDao.getOfficeCount("officename", office),10);
String limit="limit "+((p.getCurrentPage()-1)*10)+",10";
List<Office> offices = officeDao.query("officename", office,limit);
request.setAttribute("offices",offices);
request.setAttribute("office",office);
request.setAttribute("pages",p);
request.getRequestDispatcher("orderOffice.jsp").forward(request,response);
//<tr><td>姓 名:</td><td>${sessionScope.patient.name}</td></tr>
//<tr><td>预约医生:</td><td>${doctor.dname}</td></tr>
//<tr><td>预约科室:</td><td>${doctor.office} </td></tr>
//<tr><td>就诊时间:</td><td>${numSource.visitdate} ${numSource.visittime}第${numSource.serialnumber}号</td></tr>
//<tr><td>诊 查 费:</td><td>${doctor.fee}.00元</td></tr>
//<tr><td>你的邮箱:</td><td>${sessionScope.patient.email}
//<tr><td colspan="2" class="confirm">确定</td></tr>
@WebServlet(urlPatterns = "/order")
public class Order extends HttpServlet {
private HttpServletRequest req;
private HttpServletResponse resp;
private RecodeDao recodeDao = new RecodeDao();
private NumSourceDao numSourceDao = new NumSourceDao();
Patient patient;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.req = request;
this.resp = response;
patient = (Patient) req.getSession().getAttribute("patient");
String wid = req.getParameter("wid");//工作日id
String did = req.getParameter("did");//工作日id
String action = req.getParameter("action");
// String checkcode = Util.nullToString(req.getParameter("checkcode"));
String rid = req.getParameter("rid");//记录的id
String data = Util.nullToString(req.getParameter("data"));//就诊序号
String[] strings = data.split(",");
String where = "where wid=? and visitdate=? and visittime=? and state='成功'";
RecodeDao recodeDao = new RecodeDao();
switch (action) {
case "order"://准备预约
NumSource numSource = new NumSource(strings[0], strings[1], strings[2], strings[3], wid);
//HashMap<String, String> hashMap = recodeDao.confirm(id);
DoctorDao doctorDao = new DoctorDao();
List<Doctor> doctors = doctorDao.query(" where did=?", new Object[]{did});
req.getSession().setAttribute("numSource", numSource);
req.setAttribute("doctor", doctors.get(0));
req.getRequestDispatcher("confirmOrder.jsp").forward(req, resp);
break;
request.getSession().setAttribute("message",message);
// request.getSession().removeAttribute("checkCode");
response.sendRedirect("login.jsp");
return;
}else {
message="注册失败,请稍后再试!";
}
}else {
message="该账号已存在!";
}
}else {
message="请输入账号!";
}
}else {
message="两次密码不正确!";
}
request.setAttribute("message",message);
request.getRequestDispatcher("register.jsp").forward(request,response);
}
}
package com.qst.servlet.patient;
@WebServlet(urlPatterns = "/DoctorSearch")
public class DoctorSearch extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
@WebServlet(urlPatterns = "/login")
public class Login extends HttpServlet{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String account = request.getParameter("account");
String password = request.getParameter("password");
String accounttype = request.getParameter("accounttype");
request.getSession().removeAttribute("message");
// request.getSession().setAttribute("message","");
// System.out.println(url);
switch (accounttype){
case "管理员":
AdminDao adminDao=new IAdminimpl();
List<Admin> admins = adminDao.getAdmin(account);
if(admins.size()>0){
Admin admin = admins.get(0);
//用户账号密码正确
System.out.println(admin.getPassword());
System.out.println(password);
if(admin.getPassword().equals(password)){
request.getSession().setAttribute("admin",admin);
response.sendRedirect("admin/index.jsp");
}
}
break;
case "医生":
DoctorDao doctorDao=new DoctorDao();
String where="where account =?";
List<Doctor> doctors = doctorDao.query(where, new Object[]{account});
if(doctors.size()>0){
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = Util.nullToString(request.getParameter("action"));
String message="";
OfficeDao officeDao=new OfficeDao();
List<com.qst.bean.Office> offices;
switch (action){
case "add":
String officename = request.getParameter("officename");
String description = request.getParameter("description");
offices= officeDao.query("officename", officename,"");
if(offices.size()==0){
com.qst.bean.Office office = new com.qst.bean.Office(officename, description, 0);
if(officeDao.insert(office)){
message=officename+"添加成功!";
}else {
message=officename+"添加失败!";
}
}else {
message=officename+"已存在!";
}
request.setAttribute("message",message);
//req.getRequestDispatcher("admin/office.jsp").forward(req,resp);
break;
case "query":
offices = officeDao.query("officename", "","");
JSONArray array=new JSONArray();
for(com.qst.bean.Office office:offices){
JSONObject jsonObject=new JSONObject();
jsonObject.put("officename",office.getOfficename());
jsonObject.put("description",office.getDescription());
jsonObject.put("doctornum",office.getDoctornum());
array.add(jsonObject);
}
response.setContentType("application/json; charset=utf-8");
response.getWriter().write(array.toString());
return;
}
String office= Util.nullToString(request.getParameter("office"));
int start=Util.nullToZero(request.getParameter("start"));
Pages p = new Pages(start , officeDao.getOfficeCount("officename", office),10);
if(doctors.size()==0){
Doctor doctor=new Doctor();
doctor.setAccount(request.getParameter("account"));
doctor.setPassword(request.getParameter("password"));
doctor.setDname(request.getParameter("name"));
doctor.setFee(request.getParameter("fee"));
doctor.setGender(request.getParameter("gender"));
doctor.setAge(request.getParameter("age"));
doctor.setOffice(request.getParameter("office1"));
// doctor.setRoom(req.getParameter("room"));
doctor.setCareer(request.getParameter("career"));
doctor.setDescription(request.getParameter("description"));
doctor.setPicpath(request.getContextPath()+"/images/docpic/default.jpg");
if(doctorDao.insert(doctor)){
//添加医生
message="添加"+request.getParameter("name")+"医生成功!";
//科室中的医生数量加1
String where="set doctornum=? where officename=?";
OfficeDao officeDao=new OfficeDao();
String where1="where officename=?";
Office office1 =officeDao.get(where1,new Object[]{doctor.getOffice()});
// Office office1 = (Office) officeDao.query("officename", "","");
int num=office1.getDoctornum()+1;
officeDao.update(where,new Object[]{num,office1.getOfficename()});
}
}else {
message=request.getParameter("account")+"账号已存在!";
}
request.setAttribute("message",message);
}
int start = Util.nullToZero(request.getParameter("start"));
DoctorDao doctorDao=new DoctorDao();
String where="where office like ? and dname like ? ";
int total=doctorDao.getDoctorCount(where,new Object[]{Util.toLike(office),Util.toLike(name)});
Pages pages = new Pages(start , total, 6);
where+="limit "+((pages.getCurrentPage()-1)*6)+",6";
List<Doctor> doctors = doctorDao.query(where, new Object[]{Util.toLike(office),Util.toLike(name)});
request.setAttribute("doctors",doctors);
request.setAttribute("pages",pages);
request.setAttribute("doctor",name);
//OfficeDao officeDao=new OfficeDao();
//List<Office> offices = officeDao.query("officename", office, "");
request.setAttribute("office",office);
request.getRequestDispatcher("/admin/doctorManage.jsp").forward(request,response);
}
}
package com.qst.servlet;
@WebServlet(urlPatterns = "/login")
public class Login extends HttpServlet{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String account = request.getParameter("account");
String password = request.getParameter("password");
String accounttype = request.getParameter("accounttype");
request.getSession().removeAttribute("message");
// request.getSession().setAttribute("message","");
// System.out.println(url);
switch (accounttype){
case "管理员":
AdminDao adminDao=new IAdminimpl();
List<Admin> admins = adminDao.getAdmin(account);
if(admins.size()>0){
Admin admin = admins.get(0);
//用户账号密码正确
System.out.println(admin.getPassword());
System.out.println(password);
if(admin.getPassword().equals(password)){
request.getSession().setAttribute("admin",admin);
response.sendRedirect("admin/index.jsp");
}
}
break;
case "医生":
int num=office1.getDoctornum()+1;
officeDao.update(where,new Object[]{num,office1.getOfficename()});
}
}else {
message=request.getParameter("account")+"账号已存在!";
}
request.setAttribute("message",message);
}
int start = Util.nullToZero(request.getParameter("start"));
DoctorDao doctorDao=new DoctorDao();
String where="where office like ? and dname like ? ";
int total=doctorDao.getDoctorCount(where,new Object[]{Util.toLike(office),Util.toLike(name)});
Pages pages = new Pages(start , total, 6);
where+="limit "+((pages.getCurrentPage()-1)*6)+",6";
List<Doctor> doctors = doctorDao.query(where, new Object[]{Util.toLike(office),Util.toLike(name)});
request.setAttribute("doctors",doctors);
request.setAttribute("pages",pages);
request.setAttribute("doctor",name);
//OfficeDao officeDao=new OfficeDao();
//List<Office> offices = officeDao.query("officename", office, "");
request.setAttribute("office",office);
request.getRequestDispatcher("/admin/doctorManage.jsp").forward(request,response);
}
}
package com.qst.servlet;
@WebServlet(urlPatterns = "/login")
public class Login extends HttpServlet{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
public class Register extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String message="";
//得到密码
String password = request.getParameter("password");
String passwordCof = request.getParameter("passwordCof");
//判断两次密码是否相等
if(password!=null&&password.equals(passwordCof)){
//得到账号
String account=request.getParameter("account");
//判断账号是否为空
if(account!=null){
PatientDao patientDao=new PatientDao();
//从数据库中查找相同的账号记录
List<Patient> patients = patientDao.query("account", account);
//判断是否有相同的账号
if(patients.size()==0){
//得到姓名,邮箱
String name = request.getParameter("name");
String email = request.getParameter("email");
//存入新记录
Patient patient=new Patient(null,account,email,password,name,"100");
if(patientDao.insert(patient)){
message="注册成功,请登录!";
request.getSession().setAttribute("message",message);
// request.getSession().removeAttribute("checkCode");
response.sendRedirect("login.jsp");
return;
}else {
message="注册失败,请稍后再试!";
}
}else {
message="该账号已存在!";
}
}else {
message="请输入账号!";
}
}else {
message="两次密码不正确!";
}
request.setAttribute("message",message);
request.getRequestDispatcher("register.jsp").forward(request,response);
}
}
package com.qst.servlet.patient;
@WebServlet(urlPatterns= "/modifyPwd")
public class ModifyPwd extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = Util.nullToString(request.getParameter("action"));
String jmm = Util.nullToString(request.getParameter("jmm"));
String xmm = Util.nullToString(request.getParameter("xmm"));
String qdmm = Util.nullToString(request.getParameter("qdmm"));
String message="";
switch (action){
case "doctor":
Doctor doctor = (Doctor)request.getSession().getAttribute("doctor");
if(doctor.getPassword().equals(jmm)){
if(xmm.equals(qdmm)){
DoctorDao doctorDao=new DoctorDao();
String set ="set password=? where did=?";
if(doctorDao.update(set,new Object[]{xmm,doctor.getDid()})){
message="修改成功";
}else {
message="修改失败";
}
}else {
message="两次密码不一样";
}
}else {
message="密码错误";
}
request.setAttribute("message",message);
request.getRequestDispatcher("logout").forward(request,response);
// request.getRequestDispatcher("/doctor/modifyPwd.jsp").forward(request,response);
//<tr><td>姓 名:</td><td>${sessionScope.patient.name}</td></tr>
//<tr><td>预约医生:</td><td>${doctor.dname}</td></tr>
//<tr><td>预约科室:</td><td>${doctor.office} </td></tr>
//<tr><td>就诊时间:</td><td>${numSource.visitdate} ${numSource.visittime}第${numSource.serialnumber}号</td></tr>
//<tr><td>诊 查 费:</td><td>${doctor.fee}.00元</td></tr>
//<tr><td>你的邮箱:</td><td>${sessionScope.patient.email}
//<tr><td colspan="2" class="confirm">确定</td></tr>
@WebServlet(urlPatterns = "/order")
public class Order extends HttpServlet {
private HttpServletRequest req;
private HttpServletResponse resp;
private RecodeDao recodeDao = new RecodeDao();
private NumSourceDao numSourceDao = new NumSourceDao();
Patient patient;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.req = request;
this.resp = response;
patient = (Patient) req.getSession().getAttribute("patient");
String wid = req.getParameter("wid");//工作日id
String did = req.getParameter("did");//工作日id
String action = req.getParameter("action");
// String checkcode = Util.nullToString(req.getParameter("checkcode"));
String rid = req.getParameter("rid");//记录的id
String data = Util.nullToString(req.getParameter("data"));//就诊序号
String[] strings = data.split(",");
String where = "where wid=? and visitdate=? and visittime=? and state='成功'";
RecodeDao recodeDao = new RecodeDao();
switch (action) {
case "order"://准备预约
NumSource numSource = new NumSource(strings[0], strings[1], strings[2], strings[3], wid);
//HashMap<String, String> hashMap = recodeDao.confirm(id);
DoctorDao doctorDao = new DoctorDao();
List<Doctor> doctors = doctorDao.query(" where did=?", new Object[]{did});
req.getSession().setAttribute("numSource", numSource);
req.setAttribute("doctor", doctors.get(0));
doctor.setDescription(description);
// Part part;
// part = request.getPart("pic");
// if(part.getSize()>0&&part.getSize()<1024*1024){
// System.out.println(part.getSubmittedFileName());
// String fileName = part.getSubmittedFileName();
// String jpg=fileName.substring(fileName.lastIndexOf("."));
// System.out.println(jpg);
// InputStream is=part.getInputStream();
// String realPath = this.getServletContext().getRealPath("images/docpic");
// System.out.println(realPath);
// FileOutputStream fos = new FileOutputStream(realPath+"/"+doctor.getDid()+jpg);
// byte[] bytes=new byte[1024];
// int i=0;
// while ((i=is.read(bytes))!=-1){
// fos.write(bytes,0,i);
// }
// fos.close();
// is.close();
// doctor.setPicpath("/mavenHospital/images/docpic/"+doctor.getDid()+jpg);
// System.out.println(doctor.getPicpath());
// }
Object[] o=new Object[]{
doctor.getDname(),
doctor.getAge(),
doctor.getDescription(),
doctor.getDid()};
String set="set dname=?,age=?,description=? where did=?";
doctorDao.update(set,o);
}
request.getRequestDispatcher("/doctor/myInfo.jsp").forward(request,response);
}
}
package com.qst.servlet.admin;
int size=240/nsnum;
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.MINUTE,30);
/*上午8.30-12.30 4*60=240
下午1.30-5.30 4*/
if("上午".equals(ampm)){
calendar.set(Calendar.HOUR_OF_DAY,8);
}else {
calendar.set(Calendar.HOUR_OF_DAY,13);
}
// if(Integer.valueOf(workDay.getWorktime())+1==calendar.get(Calendar.DAY_OF_WEEK)){
// System.out.println("今天");
// if(calendar.get(Calendar.HOUR_OF_DAY)<){
//
// }
// }
where=" where wid=? and visitdate=? and visitnoon=? and state='成功' order by serialnumber asc";
RecodeDao recodeDao=new RecodeDao();
//查询预约表
List<Recode> recodes = recodeDao.query(where, new Object[]{wid, date, ampm});
List<NumSource> list = new ArrayList<>();
for (int i=1,j=0;i<=nsnum;i++){
String time=calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE);
NumSource numSource = new NumSource(i + "", date, ampm, time, "可预约");
if(j<recodes.size()){
if(recodes.get(j).getSerialnumber().equals(i+"")){
numSource.setState("已被预约");j++;
}
}
calendar.add(Calendar.MINUTE,size);
list.add(numSource);
}
JSONArray array=new JSONArray();
for(NumSource o:list){
//用json方式设置数据
JSONObject jsonObject=new JSONObject();
jsonObject.put("date",o.getVisitdate());
jsonObject.put("ampm",o.getVisitnoon());
jsonObject.put("serialnumber",o.getSerialnumber());
jsonObject.put("state",o.getState());
jsonObject.put("time",o.getVisittime());
array.add(jsonObject);
}
//输出结果到客户端
response.setContentType("application/json; charset=utf-8");
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
//获取前端的值
String wid = request.getParameter("wid");
String ampm =request.getParameter("ampm");
String date = request.getParameter("date");
if(wid!=null){
String where="where wid=?";
WorkDayDao workDayDao=new WorkDayDao();
//查询数据库获取值
List<WorkDay> workDays = workDayDao.query(where, new Object[]{wid});
WorkDay workDay = workDays.get(0);
//得到工作日数量
int nsnum = Integer.valueOf(workDay.getNsnum());
//计算
int size=240/nsnum;
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.MINUTE,30);
/*上午8.30-12.30 4*60=240
下午1.30-5.30 4*/
if("上午".equals(ampm)){
calendar.set(Calendar.HOUR_OF_DAY,8);
}else {
calendar.set(Calendar.HOUR_OF_DAY,13);
}
// if(Integer.valueOf(workDay.getWorktime())+1==calendar.get(Calendar.DAY_OF_WEEK)){
// System.out.println("今天");
// if(calendar.get(Calendar.HOUR_OF_DAY)<){
//
// }
// }
where=" where wid=? and visitdate=? and visitnoon=? and state='成功' order by serialnumber asc";
RecodeDao recodeDao=new RecodeDao();
//查询预约表
List<Recode> recodes = recodeDao.query(where, new Object[]{wid, date, ampm});
List<NumSource> list = new ArrayList<>();
for (int i=1,j=0;i<=nsnum;i++){
String time=calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE);
NumSource numSource = new NumSource(i + "", date, ampm, time, "可预约");
if(j<recodes.size()){
if(recodes.get(j).getSerialnumber().equals(i+"")){
numSource.setState("已被预约");j++;
}
}
return;
}else {
message="注册失败,请稍后再试!";
}
}else {
message="该账号已存在!";
}
}else {
message="请输入账号!";
}
}else {
message="两次密码不正确!";
}
request.setAttribute("message",message);
request.getRequestDispatcher("register.jsp").forward(request,response);
}
}
package com.qst.servlet.patient;
@WebServlet(urlPatterns = "/DoctorSearch")
public class DoctorSearch extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
//从前端得到数据
String office = Util.nullToString(request.getParameter("office"));
String name = Util.nullToString(request.getParameter("doctor"));
int start = Util.nullToZero(request.getParameter("start"));
DoctorDao doctorDao=new DoctorDao();
//数据库查询语句
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String account = request.getParameter("account");
String password = request.getParameter("password");
String accounttype = request.getParameter("accounttype");
request.getSession().removeAttribute("message");
// request.getSession().setAttribute("message","");
// System.out.println(url);
switch (accounttype){
case "管理员":
AdminDao adminDao=new IAdminimpl();
List<Admin> admins = adminDao.getAdmin(account);
if(admins.size()>0){
Admin admin = admins.get(0);
//用户账号密码正确
System.out.println(admin.getPassword());
System.out.println(password);
if(admin.getPassword().equals(password)){
request.getSession().setAttribute("admin",admin);
response.sendRedirect("admin/index.jsp");
}
}
break;
case "医生":
DoctorDao doctorDao=new DoctorDao();
String where="where account =?";
List<Doctor> doctors = doctorDao.query(where, new Object[]{account});
if(doctors.size()>0){
Doctor doctor = doctors.get(0);
//医生账号密码正确
if(doctor.getPassword().equals(password)){
request.getSession().setAttribute("doctor",doctor);
response.sendRedirect("doctor/index.jsp");
return;
}
}
//用户密码错误
request.getSession().setAttribute("message","用户名或密码错误!!");
request.getRequestDispatcher("doctor/login.jsp").forward(request,response);
break;
case "患者":
PatientDao patientDao=new PatientDao();
List<Patient> patients = patientDao.query("account",account);
if(patients.size()>0){
Patient patient = patients.get(0);
//判断密码是否相同
String where2 =" where wid=? ";
List<WorkDay> workDay= workDayDao.query(where2,new Object[]{wid});
String where3="set nsnum=? where wid=?";
String where4="set nsnum=? and state=? where wid=?";
int num=workDay.get(0).getNsnum()-1;
if(num!=0)
{
workDayDao.update(where3,new Object[]{num,wid});
}
else
{
workDayDao.update(where4,new Object[]{num,"停诊",wid});
}
request.getSession().setAttribute("message", "预约成功!");
request.getRequestDispatcher("orderList").forward(request, response);
} else {
req.getSession().setAttribute("message", "预约失败!");
req.getRequestDispatcher("ShowWorkday?did=" + did).forward(req, resp);
}
} else {
req.getSession().setAttribute("message", "号源已被预约!");
req.getRequestDispatcher("ShowWorkday?did=" + did).forward(req, resp);
}
break;
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.qst.servlet;
@WebServlet(urlPatterns = "/doctorManage")
public class DoctorManage extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String office = Util.nullToString(request.getParameter("office"));
String name = Util.nullToString(request.getParameter("doctor"));
String action = Util.nullToString(request.getParameter("action"));
if("add".equals(action)){
String message="增加医生失败!";
DoctorDao doctorDao = new DoctorDao();
System.out.println(request.getParameter("account"));
List<Doctor> doctors = doctorDao.query("where account=? ",new Object[]{Util.nullToString(request.getParameter("account"))});
if(doctors.size()==0){
Doctor doctor=new Doctor();
doctor.setAccount(request.getParameter("account"));
doctor.setPassword(request.getParameter("password"));
doctor.setDname(request.getParameter("name"));
doctor.setFee(request.getParameter("fee"));
doctor.setGender(request.getParameter("gender"));
doctor.setAge(request.getParameter("age"));
doctor.setOffice(request.getParameter("office1"));
// doctor.setRoom(req.getParameter("room"));
doctor.setCareer(request.getParameter("career"));
doctor.setDescription(request.getParameter("description"));
doctor.setPicpath(request.getContextPath()+"/images/docpic/default.jpg");
if(doctorDao.insert(doctor)){
//添加医生
message="添加"+request.getParameter("name")+"医生成功!";
//科室中的医生数量加1
{
workDayDao.update(where3,new Object[]{num,wid});
}
else
{
workDayDao.update(where4,new Object[]{num,"停诊",wid});
}
request.getSession().setAttribute("message", "预约成功!");
request.getRequestDispatcher("orderList").forward(request, response);
} else {
req.getSession().setAttribute("message", "预约失败!");
req.getRequestDispatcher("ShowWorkday?did=" + did).forward(req, resp);
}
} else {
req.getSession().setAttribute("message", "号源已被预约!");
req.getRequestDispatcher("ShowWorkday?did=" + did).forward(req, resp);
}
break;
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.qst.servlet;
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletRequest;
servletRequest.setCharacterEncoding("utf-8");
servletResponse.setCharacterEncoding("utf-8");
servletResponse.setContentType("text/html;charset=utf-8");
// 得到用户请求的URI
// 得到web应用程序的上下文路径
// 去除上下文路径,得到剩余部分的路径
String uri = req.getRequestURI().substring(req.getContextPath().length());//请求的页面
String url=req.getHeader("referer");//之前的页面
if(req.getSession().getAttribute("patient")==null&&patient.contains(uri)){
req.getSession().setAttribute("message","请先登录!");
req.getSession().setAttribute("url",url);
// System.out.println(req.getSession().getAttribute("url"));
HttpServletResponse resp= (HttpServletResponse) servletResponse;
resp.sendRedirect("login.jsp");
}else {
filterChain.doFilter(servletRequest, servletResponse);
}
}
@Override
public void destroy() {
}
}
package com.qst.servlet.patient;
@WebServlet(urlPatterns = "/ShowWorkday")
public class ShowWorkday extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
break;
}
PatientDao patientDao = new PatientDao();
ArrayList<HashMap<String, String>> list = patientDao.patientList(doctor.getDid());
request.setAttribute("list",list);
request.getRequestDispatcher("/doctor/patientList.jsp").forward(request,response);
}
}
package com.qst.servlet.patient;
@WebServlet(urlPatterns = "/orderList")
public class OrderList extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
Patient patient= (Patient) request.getSession().getAttribute("patient");
// RecodeDao recodeDao = new RecodeDao();
// DoctorDao doctorDao=new DoctorDao();
// String where="where pid=? order by ordertime desc";
// String where1="where pid=? order by ordertime desc";
// List<Recode> Recodelist = recodeDao.query(where, new Object[]{patient.getId()});
if(patients.size()>0){
Patient patient = patients.get(0);
//判断密码是否相同
if(patient.getPassword().equals(password)){
request.getSession().setAttribute("patient",patient);
String url= (String) request.getSession().getAttribute("url");
if(url==null)
url="index.jsp";
request.getSession().setAttribute("message","登录成功!!");
response.sendRedirect(url);
return;
}
}
request.getSession().setAttribute("message","用户名或密码错误!!");
response.sendRedirect("login.jsp");
break;
}
}
}
package com.qst.servlet;
@WebServlet(urlPatterns= "/queryNumSource")