基于javaweb的医院管理系统(java+javaweb+jdbc+Mysql+lw)
功能介绍:
登录、注册、用户/管理员(角色)、用户信息管理、科系信息管理、查看所有科系、新增科系信息、删除指定科系、修改科系信息、病房信息管理、病人信息管理、医生类型管理、病人手术管理
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
info = "错误:删除院系失败!";
}
out.write("<div class='error'>");
out.write("<div>" + info + "</div>");
out.write("</div>");
out.flush();
out.close();
}
// 修改院系
protected void alter_department(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String dno = request.getParameter("dno");
String after_dno = request.getParameter("after_dno");
String after_dname = request.getParameter("after_dname");
int flag = new SectionDao().alter_department(dno, after_dno, after_dname);
String info = null;
PrintWriter out = response.getWriter();
if (flag == 1) {
info = dno + "号系修改成功!";
} else {
info = "错误:修改院系失败!";
}
out.write("<div class='error'>");
response.setContentType("text/html;charset=utf-8");
ArrayList<Room> results = new RoomDao().query_all_class();
PrintWriter out = response.getWriter();
//输出结果
if (results != null) {
out.write("<div class='all'>");
out.write("<div><span>病房编号</span><span>病房名</span><span>所属科系</span></div>");
for (Room i : results) {
out.write("<div>");
out.write("<span>" + i.getClno() + "</span>");
out.write("<span>" + i.getClname() + "</span>");
out.write("<span>" + i.getDname() + "</span>");
out.write("</div>");
}
out.write("</div>");
}
out.flush();
out.close();
}
// 插入病房
protected void insert_class(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String clno = request.getParameter("clno");
PrintWriter out = response.getWriter();
//输出结果
if (results != null) {
out.write("<div class='all'>");
out.write("<div><span>病房编号</span><span>病房名</span><span>所属科系</span></div>");
for (Room i : results) {
out.write("<div>");
out.write("<span>" + i.getClno() + "</span>");
out.write("<span>" + i.getClname() + "</span>");
out.write("<span>" + i.getDname() + "</span>");
out.write("</div>");
}
out.write("</div>");
}
out.flush();
out.close();
}
// 插入病房
protected void insert_class(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String clno = request.getParameter("clno");
String clname = request.getParameter("clname");
String dname = request.getParameter("dname");
}
out.write("<div class='error'>");
out.write("<div>"+info+"</div>");
out.write("</div>");
out.flush();
out.close();
}
//修改用户
protected void alter_user(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String username = request.getParameter("username");
String after_username = request.getParameter("after_username");
String after_password = request.getParameter("after_password");
String after_level = request.getParameter("after_level");
int flag = new UserDao().alter_user(username,after_username,after_password,after_level);
String info = null;
out.write("<div class='error'>");
out.write("<div>" + info + "</div>");
out.write("</div>");
out.flush();
out.close();
}
/*-------------------------------- 病人-----------------------------------*/
// 查询所有病人
protected void query_all_student(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
ArrayList<Patient> results = new PatientDao().query_all_student();
PrintWriter out = response.getWriter();
// 输出结果
if (results != null) {
out.write("<div class='all'>");
out.write("<div><span>病人号</span><span>姓名</span><span>性别</span><span>年龄</span><span>所在病房</span></div>");
for (Patient i : results) {
out.write("<div>");
out.write("<span>" + i.getSno() + "</span>");
out.write("<span>" + i.getSname() + "</span>");
out.write("<span>" + i.getSsex() + "</span>");
out.write("<span>" + i.getSage() + "</span>");
out.write("<span>" + i.getClname() + "</span>");
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String clno = request.getParameter("clno");
int flag = new RoomDao().delete_class(clno);
String info = null;
PrintWriter out = response.getWriter();
if (flag == 1) {
info = "成功删除" + clno + "病房!";
} else {
info = "错误:删除病房失败!";
}
out.write("<div class='error'>");
out.write("<span>" + i.getCteacher() + "</span>");
out.write("<span>" + i.getCname() + "</span>");
out.write("<span>" + i.getGrade() + "</span>");
out.write("</div>");
}
out.write("</div>");
}
out.flush();
out.close();
}
// 插入一条手术记录
protected void insert_sc(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String sno = request.getParameter("sno");
String cteacher = request.getParameter("cteacher");
double grade = Double.parseDouble(request.getParameter("grade"));
out.write("<div class='error'>");
out.write("<div>" + info + "</div>");
out.write("</div>");
out.flush();
out.close();
}
登录服务类:
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String username = request.getParameter("username");
case "alter_user":
alter_user(request, response);break;
//系别操作
case "query_all_department":
query_all_department(request, response);break;
case "insert_department":
insert_department(request, response);break;
case "delete_department":
delete_department(request, response);break;
case "alter_department":
alter_department(request, response);break;
//病房操作
out.write("<span>" + i.getClno() + "</span>");
out.write("<span>" + i.getClname() + "</span>");
out.write("<span>" + i.getDname() + "</span>");
out.write("</div>");
}
out.write("</div>");
}
out.flush();
out.close();
}
// 插入病房
protected void insert_class(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String clno = request.getParameter("clno");
String clname = request.getParameter("clname");
String dname = request.getParameter("dname");
int flag = new RoomDao().insert_class(clno, clname, dname);
String info = null;
ArrayList<Section> results = new SectionDao().query_all_department();
PrintWriter out = response.getWriter();
// 输出结果
if (results != null) {
out.write("<div class='all'>");
out.write("<div><span>系编号</span><span>系名</span></div>");
for (Section i : results) {
out.write("<div>");
out.write("<span>" + i.getDno() + "</span>");
out.write("<span>" + i.getDname() + "</span>");
out.write("</div>");
}
out.write("</div>");
}
out.flush();
out.close();
}
// 插入院系
}
用户管理控制层:
public class UserExitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//获取Session
HttpSession session = request.getSession();
session.invalidate();
//转发到login.html页面
response.sendRedirect("login.html");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
管理员服务类:
public class AdminDao extends HttpServlet {
private static final long serialVersionUID = 1L;
private String action;//存储操作描述
//接收请求
// 查询所有院系
protected void query_all_department(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
ArrayList<Section> results = new SectionDao().query_all_department();
PrintWriter out = response.getWriter();
// 输出结果
if (results != null) {
out.write("<div class='all'>");
out.write("<div><span>系编号</span><span>系名</span></div>");
for (Section i : results) {
out.write("<div>");
out.write("<span>" + i.getDno() + "</span>");
out.write("<span>" + i.getDname() + "</span>");
out.write("</div>");
}
out.write("</div>");
}
out.flush();
out.close();
}
case "alter_class":
alter_class(request, response);break;
//病人操作
case "query_all_student":
query_all_student(request, response);break;
case "insert_student":
insert_student(request, response);break;
case "delete_student":
delete_student(request, response);break;
case "alter_student":
alter_student(request, response);break;
//医生操作
case "query_all_course":
query_all_course(request, response);break;
case "insert_course":
}
//删除用户
protected void delete_user(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String username = request.getParameter("username");
int flag = new UserDao().delete_user(username);
String info = null;
PrintWriter out = response.getWriter();
if(flag == 1){
info = "成功删除名为"+username+"用户!";
}else{
info = "错误:删除用户失败!";
}
out.write("<div class='error'>");
out.write("<div>"+info+"</div>");
out.write("</div>");
out.flush();
out.close();
}
//修改用户
int flag = new UserDao().alter_user(username,after_username,after_password,after_level);
String info = null;
PrintWriter out = response.getWriter();
if(flag == 1){
info = "名为"+username+"用户信息修改成功!";
}else{
info = "错误:修改用户失败!";
}
out.write("<div class='error'>");
out.write("<div>"+info+"</div>");
out.write("</div>");
out.flush();
out.close();
}
/*-------------------------------- 院系-----------------------------------*/
String cteacher = request.getParameter("cteacher");
double after_grade = Double.parseDouble(request.getParameter("after_grade"));
int flag = new OperationDao().alter_sc(sno, cteacher, after_grade);
String info = null;
PrintWriter out = response.getWriter();
if (flag == 1) {
info = sno + "号病人" + cteacher + "号手术记录修改成功!";
} else {
info = "错误:修改手术记录失败!";
}
out.write("<div class='error'>");
out.write("<div>" + info + "</div>");
out.write("</div>");
out.flush();
out.close();
}
登录服务类:
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (results != null) {
out.write("<div class='all'>");
out.write("<div><span>系编号</span><span>系名</span></div>");
for (Section i : results) {
out.write("<div>");
out.write("<span>" + i.getDno() + "</span>");
out.write("<span>" + i.getDname() + "</span>");
out.write("</div>");
}
out.write("</div>");
}
info = "错误:病人插入失败!";
}
out.write("<div class='error'>");
out.write("<div>" + info + "</div>");
out.write("</div>");
out.flush();
out.close();
}
// 删除病人
protected void delete_student(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String sno = request.getParameter("sno");
int flag = new PatientDao().delete_student(sno);
String info = null;
PrintWriter out = response.getWriter();
String info = null;
PrintWriter out = response.getWriter();
if (flag == 1) {
info = "病房"+clno+"修改成功!";
} else {
info = "错误:修改病房失败!";
}
out.write("<div class='error'>");
out.write("<div>" + info + "</div>");
out.write("</div>");
out.flush();
out.close();
}
/*-------------------------------- 病人-----------------------------------*/
// 查询所有病人
protected void query_all_student(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
ArrayList<Patient> results = new PatientDao().query_all_student();
PrintWriter out = response.getWriter();
// 输出结果
if (results != null) {
out.write("<div class='all'>");
out.write("</div>");
out.flush();
out.close();
}
/*-------------------------------- 病人-----------------------------------*/
// 查询所有病人
protected void query_all_student(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
ArrayList<Patient> results = new PatientDao().query_all_student();
PrintWriter out = response.getWriter();
//判断是否登录成功
if(user != null){//成功
level = user.getLevel();
//判断权限
if(level.equals("用户")){
//将用户对象放到session中
request.getSession().setAttribute("user", user);
//转发到user.jsp中
request.getRequestDispatcher("user.jsp").forward(request, response);
}
else{
//将管理员对象放到session中
request.getSession().setAttribute("admin", user);
//转发到admin.jsp中
request.getRequestDispatcher("admin.jsp").forward(request, response);
}
}else {
//失败
request.setAttribute("info"," 错误:用户名或密码错误!");
String Cno = request.getParameter("cno");
String Cname = request.getParameter("cname");
String Cteacher = request.getParameter("cteacher");
int Ccredit = Integer.parseInt(request.getParameter("ccredit"));
int flag = new DoctorDao().insert_course(Cno, Cname, Cteacher, Ccredit);
String info = null;
PrintWriter out = response.getWriter();
if(flag == 1){
info = "医生"+Cname+"插入成功!";
}else{
info = "错误:医生插入失败!";
}
out.write("<div class='error'>");
out.write("<div>"+info+"</div>");
out.write("</div>");
out.write("<span>" + i.getSsex() + "</span>");
out.write("<span>" + i.getSage() + "</span>");
out.write("<span>" + i.getCteacher() + "</span>");
out.write("<span>" + i.getCname() + "</span>");
out.write("<span>" + i.getGrade() + "</span>");
out.write("</div>");
}
out.write("</div>");
}
out.flush();
out.close();
}
// 插入一条手术记录
protected void insert_sc(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String sno = request.getParameter("sno");
String cteacher = request.getParameter("cteacher");
double grade = Double.parseDouble(request.getParameter("grade"));
}
out.flush();
out.close();
}
// 插入病房
protected void insert_class(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
String clno = request.getParameter("clno");
String clname = request.getParameter("clname");
String dname = request.getParameter("dname");
int flag = new RoomDao().insert_class(clno, clname, dname);
String info = null;
PrintWriter out = response.getWriter();
if (flag == 1) {
info = "病房"+clname+"插入成功!";
} else {
info = "错误:病房插入失败!";
}
out.write("<div class='error'>");