package servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import entity.User;
import service.UserService;
import service.impl.UserServiceImpl;
import utils.WebUtils;
/**
* Servlet implementation class UserServlet
*/
public class UserServlet extends HttpServlet {
private UserService service=new UserServiceImpl();
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action=request.getParameter("action");//接受请求的参数
if(action!=null&action.equals("login")) {//处理登录
login(request, response);
}else if(action!=null&action.equals("toRegsite")) {//跳转到注册界面
toRegsite(request, response);
}else if(action!=null&action.equals("registe")) {//进行注册
registe(request,response);
}else if(action!=null&action.equals("LoginOutAct")){//退出登录
loginOut(request,response);
}else if(action!=null&action.equals("userListAct")) {//用户列表
list(request, response);
}else if(action!=null&action.equals("toAddUserAct")) {//跳转到添加用户
toAddUser(request,response);
}else if(action!=null&action.equals("welcome")) {//跳转到控制台
welcome(request,response);
}else if(action!=null&action.equals("toLoginAct")) {//跳转到登录界面
toLogin(request,response);
}else if(action!=null&action.equals("findByUserNameAct")) {//根据条件查询
findByMap(request,response);
}else if(action!=null&action.equals("queryByIdAct")) {//根据条件查询
query(request,response);
}else if(action!=null&action.equals("deleteUserAct")) {//根据id删除
delete(request,response);
}else if(action!=null&action.equals("addUserAct")) {//根据id删除
add(request,response);
}else if(action!=null&action.equals("findMyInfoAct")) {//根据id删除
findMyInfo(request,response);
}else if(action!=null&action.equals("updateUserAct")) {//根据id删除
update(request,response);
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//处理登录
String username = request.getParameter("username");
String password = request.getParameter("password");
int type = Integer.parseInt(request.getParameter("type"));
User user = service.login(new User(null, username, password,null, type));
switch (type) {
case 1:
if (user == null){
request.setAttribute("message", "用户不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
} else if(user.getType()!=1){
request.setAttribute("message", "用户名和用户类型不匹配,请重新输入!");
request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("user",user);
request.getSession().setAttribute("flag",1);
request.getRequestDispatcher("/WEB-INF/jsp/main.jsp").forward(request, response);
}
break;
default:
if (user == null){
request.setAttribute("message", "管理员不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
} else if(user.getType()!=2){
request.setAttribute("message", "用户名和用户类型不匹配,请重新输入!");
request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("user",user);
request.getSession().setAttribute("flag",2);
request.getRequestDispatcher("/WEB-INF/jsp/main.jsp").forward(request, response);
}
break;
}
}
//分页查询
protected void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//跳转到注册界面
String p=request.getParameter("p");//接收页码
//System.out.println(p);
int pageSize=6;//每页显示5条
int pageNum=1; //默认第一页
if(p!=null){
pageNum= Integer.parseInt(p);
}
//调用分页查询
List<User> bList=service.getPage(pageNum,pageSize);
//携带参数到页面
request.setAttribute("userList",bList); //绑定参数
int nums=service.queryCount(); //查询总数
//计算总页数
int totalPage=(nums%pageSize==0)? (nums/pageSize):(nums/pageSize+1);
request.setAttribute("cp",pageNum); //当前页
request.setAttribute("tp",totalPage); //总页数
//条件 值1:值2
request.getRequestDispatcher("/WEB-INF/jsp/user_list.jsp").forward(request,response); //页面转发
}
protected void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//添加
String username=request.getParameter("username");
String password=request.getParameter("password");
String email=request.getParameter("email");
int type=Integer.parseInt(request.getParameter("type"));
if(service.existsUsername(username)){
request.setAttribute("msg","用户名已存在");
request.setAttribute("username",username);
request.setAttribute("email",email);
response.sendRedirect(request.getContextPath()+"/UserServlet?action=userListAct");//重定向防止重复提交哦
}else {
service.registerUser(new User(null,username,password,email,type));
response.sendRedirect(request.getContextPath()+"/UserServlet?action=userListAct");//重定向防止重复提交哦
}
}
protected void query(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//查询数据并回显
int id=WebUtils.parseInt(request.getParameter("id"),0);
User user=service.queryById(id);
request.setAttribute("list",user);
System.out.println(user);
request.getRequestDispatcher("/WEB-INF/jsp/update_user.jsp").forward(request,response);
}
protected void findMyInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//查询个人信息
String username=request.getParameter("username");
User user=service.findByUserName(username);
request.setAttribute("user",user);
System.out.println(user);
request.getRequestDispatcher("/WEB-INF/jsp/user_info.jsp").forward(request,response);
}
protected void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//更改
int id= WebUtils.parseInt(request.getParameter("id"),0);
String username=request.getParameter("username");
String password=request.getParameter("password");
String email=request.getParameter("email");
int type=Integer.parseInt(request.getParameter("type"));
String flag=request.getParameter("flag");
if (flag.equals("1")) {
service.update(new User(id,username,password,email,type));
request.getRequestDispatcher("/WEB-INF/jsp/update_ok.jsp")
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java web+layui框架的医院住院信息管理系统(源码+数据库脚本).zip
共104个文件
js:23个
jsp:15个
class:15个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 185 浏览量
2023-02-13
22:42:54
上传
评论
收藏 3.18MB ZIP 举报
温馨提示
使用说明:将源码导入Java ee工具,将sql数据库脚本导入MySQL数据库,修改数据库连接语句,调试运行。界面优美,操作简单,适用于课程设计或者毕业设计参考使用。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java web+layui框架的医院住院信息管理系统(源码+数据库脚本).zip (104个子文件)
UserServlet.class 8KB
UserDaoImpl.class 5KB
RecordServlet.class 5KB
RecordDaoImpl.class 5KB
Record.class 3KB
UserServiceImpl.class 2KB
User.class 2KB
RecordServiceImpl.class 2KB
WebUtils.class 1KB
EncodingFilter.class 1KB
C3p0Utils.class 1KB
UserService.class 712B
UserDao.class 665B
RecordService.class 527B
RecordDao.class 504B
.classpath 851B
org.eclipse.wst.common.component 500B
org.eclipse.wst.jsdt.ui.superType.container 49B
layui.css 82KB
admin.css 23KB
layer.css 14KB
layui.mobile.css 11KB
laydate.css 7KB
login.css 3KB
code.css 1KB
loading-0.gif 6KB
loading-2.gif 2KB
loading-1.gif 701B
mysql-connector-java-5.1.48.jar 983KB
mchange-commons-java-0.2.12.jar 604KB
c3p0-0.9.5.2.jar 486KB
standard.jar 384KB
gson-2.8.4.jar 235KB
commons-beanutils-1.8.0.jar 226KB
commons-dbutils-1.7.jar 95KB
javax.servlet-api-3.0.1.jar 83KB
commons-logging-1.1.1.jar 59KB
jstl.jar 20KB
UserServlet.java 12KB
RecordServlet.java 6KB
UserDaoImpl.java 5KB
RecordDaoImpl.java 4KB
Record.java 2KB
UserServiceImpl.java 1KB
User.java 1KB
EncodingFilter.java 1KB
RecordServiceImpl.java 1KB
UserService.java 919B
WebUtils.java 751B
UserDao.java 694B
C3p0Utils.java 614B
RecordDao.java 483B
RecordService.java 483B
layui.all.js 271KB
jquery.js 95KB
jquery-1.9.1.min.js 91KB
table.js 31KB
mobile.js 31KB
laydate.js 27KB
layer.js 22KB
layedit.js 12KB
colorpicker.js 11KB
tree.js 11KB
form.js 9KB
upload.js 7KB
element.js 7KB
slider.js 7KB
layui.js 7KB
transfer.js 6KB
laypage.js 4KB
carousel.js 4KB
util.js 4KB
rate.js 3KB
flow.js 2KB
laytpl.js 2KB
code.js 1KB
.jsdtscope 567B
main.jsp 7KB
add_record.jsp 6KB
update_record.jsp 6KB
register.jsp 6KB
record_list.jsp 5KB
user_list.jsp 5KB
update_user.jsp 4KB
add_user.jsp 4KB
login.jsp 4KB
list_record.jsp 4KB
user_info.jsp 4KB
list_user.jsp 3KB
console.jsp 2KB
update_ok.jsp 1KB
index.jsp 497B
MANIFEST.MF 39B
org.eclipse.wst.jsdt.ui.superType.name 6B
icon.png 11KB
icon-ext.png 6KB
org.eclipse.jdt.core.prefs 364B
.project 916B
db_hospital_zy.sql 3KB
db_hospital_zy.sql 3KB
共 104 条
- 1
- 2
资源评论
等天晴i
- 粉丝: 5850
- 资源: 10万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功