package com.controller;
import com.pojo.Provider;
import com.pojo.User;
import com.service.UserService;
import com.utils.Md5Utils;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;
import java.util.List;
import java.util.Objects;
@WebServlet("/user/*")
public class UserServlet extends BaseServlet {
private UserService us = new UserService();
private Integer currentPageNo = 1;
private Integer pageSize = 8;
public void userlist(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// List<User> users = us.selectByPage(0, pageSize);
List<User> users = us.queryUserAll();
req.getSession().setAttribute("userList", users);
// req.getSession().getAttribute("userList");
// req.getSession().setAttribute("totalCount",users.size());
// req.getSession().setAttribute("currentPageNo",1);
List<User> listThis = us.getUsers(currentPageNo, pageSize);
req.getSession().setAttribute("SERVLET_NOW","user");
req.getSession().setAttribute("userList", listThis);
req.getSession().setAttribute("currentPageNo", currentPageNo);
req.getSession().setAttribute("totalCount", users.size());
if (users.size()!=0){
req.getSession().setAttribute("totalPageCount", ((users.size()-1)/ pageSize)+1);
}else {
req.getSession().setAttribute("totalPageCount", 0 );
}
resp.sendRedirect(req.getContextPath() + "/jsp/userlist.jsp");
}
public void addUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
int userCode = Integer.parseInt(req.getParameter("userCode"));
String userName = req.getParameter("userName");
String userPassword = req.getParameter("userPassword");
String ruserPassword = req.getParameter("ruserPassword");
Boolean gender = Boolean.parseBoolean(req.getParameter("gender"));
Date birthday = Date.valueOf(req.getParameter("birthday"));
String phone = req.getParameter("phone");
String address = req.getParameter("address");
String userRoleName = req.getParameter("userRoleName");
if (us.exit(userName)) {
req.getSession().setAttribute("EXIT_USER", "用户名已存在");
// resp.sendRedirect(req.getContextPath() + "/jsp/useradd.jsp");
req.getRequestDispatcher("/jsp/useradd.jsp").forward(req, resp);
} else {
User u = new User(userCode, userName, gender, userPassword, ruserPassword, phone, address, userRoleName, birthday);
boolean b = us.addUser(u.getUserCode(), u.getUserName(), u.getRuserPassword(), u.getRuserPassword(), u.isGender(), u.getBirthday(), u.getPhone(), u.getAddress(), u.getUserRoleName());
if (b) {
resp.sendRedirect(req.getContextPath() + "/user/userlist");
} else {
resp.sendRedirect(req.getContextPath() + "/jsp/useradd.jsp");
}
}
}
public void edituser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String id = req.getParameter("id");
User user = us.queryById(id);
req.getSession().setAttribute("USER", user);
Object user1 = req.getSession().getAttribute("USER");
req.getSession().setAttribute("id", user.getId());
resp.sendRedirect(req.getContextPath() + "/jsp/usermodify.jsp");
}
public void edituser1(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String id = String.valueOf(req.getSession().getAttribute("id"));
String userName = req.getParameter("userName");
Boolean gender = Boolean.parseBoolean(req.getParameter("gender"));
Date birthday = Date.valueOf(req.getParameter("birthday"));
String phone = req.getParameter("phone");
String userRoleName = req.getParameter("userRoleName");
boolean b = us.updateUser(id, userName, gender, birthday, phone, userRoleName);
resp.sendRedirect(req.getContextPath() + "/user/userlist");
}
public void viewuser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String id = req.getParameter("id");
User user = us.queryById(id);
req.getSession().setAttribute("user", user);
req.setAttribute("PWD_MSG", "两次密码不一致");
resp.sendRedirect(req.getContextPath() + "/jsp/userview.jsp");
}
public void deleteuser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String id = req.getParameter("id");
System.out.println(id);
us.deleteById(id);
resp.sendRedirect(req.getContextPath() + "/user/userlist");
}
public void reasch(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String queryname = req.getParameter("queryname");
String queryRoleName = req.getParameter("queryRoleName");
UserService us = new UserService();
List<User> users = us.queryByName(queryname, queryRoleName);
req.getSession().setAttribute("userList", users);
req.getSession().setAttribute("queryUserName", queryname);
req.getSession().setAttribute("queryuserRoleName", queryRoleName);
resp.sendRedirect(req.getContextPath() + "/jsp/userlist.jsp");
}
public void pwdModify(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
UserService service = new UserService();
String oldpassword = req.getParameter("oldpassword");
// String username = (String) req.getSession().getAttribute("LOGIN_NAME");
String username = "xiaowan";
User user = service.getUser(username);
oldpassword = Md5Utils.MD5Encode(oldpassword, "utf-8", false);
if (!user.getUserPassword().equals(oldpassword)) {
req.getSession().setAttribute("PWD_MSG", "密码输入有误");
// resp.sendRedirect(req.getContextPath() + "/jsp/pwdmodify.jsp");
req.getRequestDispatcher("/jsp/pwdmodify.jsp").forward(req,resp);
} else {
String newpassword = req.getParameter("newpassword");
String rnewpassword = req.getParameter("rnewpassword");
if (!Objects.equals(newpassword, rnewpassword)) {
req.getSession().setAttribute("PWD_MSG", "两次密码不一致");
// resp.sendRedirect(req.getContextPath() + "/jsp/pwdmodify.jsp");
req.getRequestDispatcher("/jsp/pwdmodify.jsp").forward(req,resp);
} else {
newpassword = Md5Utils.MD5Encode(newpassword, "utf-8", false);
service.pwdModify(username, newpassword);
req.getSession().setAttribute("PWD_MSG", "修改成功");
// req.getRequestDispatcher("pwdModefyMsg").forward(req,resp);
// resp.sendRedirect(req.getContextPath() + "/jsp/pwdmodify.jsp");
req.getRequestDispatcher("/jsp/pwdmodify.jsp").forward(req,resp);
}
}
}
public void pwdMsgClear(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.getSession().setAttribute("PWD_MSG",null);
// resp.sendRedirect(req.getContextPath()+"/jsp/pwdmodify.jsp");
req.getRequestDispatcher("/jsp/pwdmodify.jsp").forward(req,resp);
}
public void pageFirst(HttpServletRequest req, HttpServletResponse resp) throws IOException{
currentPageNo = 1;
resp.sendRedirect("userlist");
}
public void pageBefore(HttpServletRequest req, HttpServletResponse resp) thro
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。 基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下载即用。基于Javaweb的超市订单管理系统源码+数据库.zip 95分以上的课程设计,代码完整,下
资源推荐
资源详情
资源评论
收起资源包目录
基于Javaweb的超市订单管理系统源码+数据库(95分以上课设项目).zip (135个子文件)
layui.css 78KB
layer.css 14KB
style.css 9KB
laydate.css 7KB
public.css 6KB
datepicker.css 4KB
datepicker.css 3KB
code.css 1KB
WdatePicker.css 149B
iconfont.eot 46KB
loading-0.gif 6KB
loading-2.gif 2KB
img.gif 2KB
img.gif 2KB
datePicker.gif 1KB
loading-1.gif 701B
.gitignore 18B
My97DatePicker.htm 1KB
SM.iml 1KB
mysql-connector-java-5.1.35.jar 946KB
jstl-impl.jar 379KB
commons-beanutils-1.9.4.jar 241KB
commons-lang-2.1.jar 203KB
commons-dbcp-1.4.jar 157KB
commons-pool-1.5.6.jar 98KB
ezmorph-1.0.2.jar 76KB
json-lib-1.1-jdk13.jar 65KB
commons-logging-1.1.1.jar 59KB
jstl.jar 20KB
UserServlet.java 13KB
JDBCUtils.java 11KB
BillServlet.java 9KB
ProviderServlet.java 7KB
DSUtil.java 6KB
User.java 4KB
UserDao.java 3KB
Provider.java 3KB
UserService.java 2KB
Bill.java 2KB
ProviderDao.java 2KB
Md5Utils.java 2KB
RandomCodeServlet.java 2KB
LoginServlet.java 2KB
LoginFilter.java 2KB
DemoServlet.java 1KB
ProviderService.java 1KB
BillDao.java 1KB
Result.java 1KB
BaseServlet.java 1KB
isNameExidServlet.java 902B
BillService.java 677B
LoginService.java 528B
LoginDao.java 385B
login_bg.jpg 45KB
clock.jpg 22KB
loginBg.jpg 18KB
bg.jpg 307B
layui.js 284KB
jquery-3.6.0.js 136KB
jquery-1.8.3.min.js 91KB
calendar.js 19KB
WdatePicker.js 8KB
useradd.js 7KB
billadd.js 5KB
billmodify.js 5KB
usermodify.js 4KB
pwdmodify.js 3KB
providerlist.js 3KB
provideradd.js 3KB
userlist.js 3KB
billlist.js 3KB
providermodify.js 2KB
zh-cn.js 1KB
zh-tw.js 1KB
time.js 993B
en.js 631B
common.js 511B
rollpage.js 485B
providerview.js 318B
billview.js 318B
userview.js 318B
config.js 212B
billlist.jsp 7KB
layuiList.jsp 4KB
providerlist.jsp 4KB
useradd.jsp 4KB
billmodify.jsp 3KB
userlist.jsp 3KB
rollpage.jsp 3KB
edit.jsp 3KB
providermodify.jsp 3KB
provideradd.jsp 3KB
billadd.jsp 3KB
head.jsp 3KB
usermodify.jsp 2KB
login.jsp 2KB
pwdmodify.jsp 2KB
billview.jsp 2KB
providerview.jsp 1KB
jqueryDemo.jsp 1KB
共 135 条
- 1
- 2
资源评论
- mym121527102024-03-22资源很实用,对我启发很大,有很好的参考价值,内容详细。
- m0_657338172023-10-31这个资源内容超赞,对我来说很有价值,很实用,感谢大佬分享~
盈梓的博客
- 粉丝: 6845
- 资源: 1247
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功