package com.github.servlet.user;
import com.alibaba.fastjson.JSONArray;
import com.github.pojo.Role;
import com.github.pojo.User;
import com.github.service.role.RoleService;
import com.github.service.role.RoleServiceImpl;
import com.github.service.user.UserService;
import com.github.service.user.UserServiceImpl;
import com.github.util.Constants;
import com.github.util.PageSupport;
import com.mysql.jdbc.StringUtils;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UserServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String method = request.getParameter("method");
System.out.println("method----> " + method);
if(method != null && method.equals("savepwd")){
this.updatePwd(request, response);
} else if(method.equals("pwdmodify") && method!=null){
this.pwdModify(request,response);
} else if(method != null && method.equals("query")) {
this.query(request,response);
} else if(method != null && method.equals("add")){
this.add(request, response);
} else if(method != null && method.equals("getrolelist")){
this.getRoleList(request, response);
} else if(method != null && method.equals("ucexist")){
this.userCodeExist(request, response);
} else if(method != null && method.equals("deluser")){
this.delUser(request, response);
} else if(method != null && method.equals("view")){
this.getUserById(request, response,"userview.jsp");
} else if(method != null && method.equals("modify")){
this.getUserById(request, response,"usermodify.jsp");
} else if(method != null && method.equals("modifyexe")){
this.modify(request, response);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String method = request.getParameter("method");
System.out.println("method----> " + method);
if(method != null && method.equals("savepwd")){
this.updatePwd(request, response);
} else if(method.equals("pwdmodify") && method!=null){
this.pwdModify(request,response);
} else if(method != null && method.equals("query")) {
this.query(request,response);
} else if(method != null && method.equals("add")){
this.add(request, response);
} else if(method != null && method.equals("getrolelist")){
this.getRoleList(request, response);
} else if(method != null && method.equals("ucexist")){
this.userCodeExist(request, response);
} else if(method != null && method.equals("deluser")){
this.delUser(request, response);
} else if(method != null && method.equals("view")){
this.getUserById(request, response,"userview.jsp");
} else if(method != null && method.equals("modify")){
this.getUserById(request, response,"usermodify.jsp");
} else if(method != null && method.equals("modifyexe")){
this.modify(request, response);
}
}
// 修改密码
public void updatePwd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 从Session中取ID
Object o = request.getSession().getAttribute(Constants.USER_SESSION);
String newpassword = request.getParameter("newpassword");
System.out.println("UserServlet3:"+newpassword);
boolean flag = false;
if(o != null && !StringUtils.isNullOrEmpty(newpassword)){
UserService userService = new UserServiceImpl();
flag = userService.updatePwd(((User)o).getId(),newpassword);
if(flag){
request.setAttribute(Constants.SYS_MESSAGE, "修改密码成功,请退出并使用新密码重新登录!");
// 密码修改成功,session注销
request.getSession().removeAttribute(Constants.USER_SESSION);
}else{
request.setAttribute(Constants.SYS_MESSAGE, "修改密码失败!");
}
}else{
request.setAttribute(Constants.SYS_MESSAGE, "修改密码失败!");
}
request.getRequestDispatcher("pwdmodify.jsp").forward(request, response);
}
// 验证旧密码,session中有用户的密码
public void pwdModify(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// 从Session中取ID
Object o = req.getSession().getAttribute(Constants.USER_SESSION);
String oldpassword = req.getParameter("oldpassword");
Map<String, String> resultMap = new HashMap<String, String>();
// session过期
if(null == o ){
resultMap.put("result", "sessionerror");
}else if(StringUtils.isNullOrEmpty(oldpassword)){
// 旧密码输入为空
resultMap.put("result", "error");
}else{
String sessionPwd = ((User)o).getUserPassword();
if(oldpassword.equals(sessionPwd)){
resultMap.put("result", "true");
}else{
// 旧密码输入不正确
resultMap.put("result", "false");
}
}
resp.setContentType("application/json");
PrintWriter outWriter = resp.getWriter();
// JSONArray 阿里巴巴的JSON工具类
outWriter.write(JSONArray.toJSONString(resultMap));
outWriter.flush();
outWriter.close();
}
// 用户管理
public void query(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 查询用户列表
String queryUserName = request.getParameter("queryname");
String temp = request.getParameter("queryUserRole");
String pageIndex = request.getParameter("pageIndex");
int queryUserRole = 0;
UserService userService = new UserServiceImpl();
List<User> userList = null;
// 设置页面容量
int pageSize = Constants.pageSize;
// 当前页码
int currentPageNo = 1;
/**
* http://localhost:8090/SMBMS/userlist.do
* ----queryUserName --NULL
* http://localhost:8090/SMBMS/userlist.do?queryname=
* --queryUserName ---""
*/
System.out.println("queryUserName servlet-------->"+queryUserName);
System.out.println("queryUserRole servlet-------->"+queryUserRole);
System.out.println("query pageIndex----------> " + pageIndex);
if(queryUserName == null){
queryUserName = "";
}
if(temp != null && !temp.equals("")){
queryUserRole = Integer.parseInt(temp);
}
if(pageIndex != null){
try{
currentPageNo = Integer.valueOf(pageIndex);
}catch(NumberFormatException e){
response.sendRedirect("error.jsp");
}
}
// 获取用户总数
int totalCount = userService.getUserCount(queryUserName,queryUserRole);
// 总页数
PageSupport pages=new PageSupport();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
// 控制首页和尾页
if(currentPageNo < 1){
currentPageNo = 1;
}else if(currentPageNo > totalPageCount){
currentPageNo = totalPageCount;
}
us
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
内容概要:项目是一个Java项目,使用的技术是JSP+Servlet+JavaBean+JDBC。 适用人群:初学Java的学员的练习小程序管理系统。 使用场景及目标:这是一个超市订单管理系统,练习项目的增删改查功能及了解处理过程。 其他说明:学习项目要安装初学的必要软件,如JDK8, IDEA, MYSQL,Maven等软件。
资源推荐
资源详情
资源评论
收起资源包目录
Java超市订单管理系统 (263个子文件)
$PROJECT_FILE$ 364B
UserServlet.class 11KB
UserServlet.class 11KB
BillServlet.class 8KB
BillServlet.class 8KB
User.class 8KB
User.class 8KB
UserDaoImpl.class 8KB
UserDaoImpl.class 8KB
Bill.class 7KB
Bill.class 7KB
BillDaoImpl.class 7KB
BillDaoImpl.class 7KB
ProviderServlet.class 7KB
ProviderServlet.class 7KB
Provider.class 6KB
Provider.class 6KB
ProviderDaoImpl.class 6KB
ProviderDaoImpl.class 6KB
UserServiceImpl.class 6KB
UserServiceImpl.class 6KB
ProviderServiceImpl.class 4KB
ProviderServiceImpl.class 4KB
Role.class 4KB
Role.class 4KB
BillServiceImpl.class 4KB
BillServiceImpl.class 4KB
BaseDao.class 3KB
BaseDao.class 3KB
LoginServlet.class 2KB
LoginServlet.class 2KB
RoleServiceImpl.class 2KB
RoleServiceImpl.class 2KB
RoleDaoImpl.class 2KB
RoleDaoImpl.class 2KB
SysFilter.class 2KB
SysFilter.class 2KB
PageSupport.class 1KB
PageSupport.class 1KB
CharacterEncodingFilter.class 1KB
CharacterEncodingFilter.class 1KB
LogoutServlet.class 1KB
LogoutServlet.class 1KB
UserDao.class 853B
UserDao.class 853B
ProviderDao.class 699B
ProviderDao.class 699B
BillDao.class 680B
BillDao.class 680B
UserService.class 655B
UserService.class 655B
ProviderService.class 518B
ProviderService.class 518B
BillService.class 454B
BillService.class 454B
Constants.class 448B
Constants.class 448B
RoleDao.class 315B
RoleDao.class 315B
RoleService.class 235B
RoleService.class 235B
style.css 9KB
style.css 9KB
public.css 6KB
public.css 6KB
datepicker.css 4KB
datepicker.css 4KB
datepicker.css 3KB
datepicker.css 3KB
WdatePicker.css 149B
WdatePicker.css 149B
img.gif 2KB
img.gif 2KB
img.gif 2KB
img.gif 2KB
datePicker.gif 1KB
datePicker.gif 1KB
.gitignore 221B
My97DatePicker.htm 1KB
My97DatePicker.htm 1KB
SMBMS.iml 639B
SMBMS.iml 466B
UserServlet.java 15KB
BillServlet.java 11KB
UserDaoImpl.java 9KB
ProviderServlet.java 8KB
BillDaoImpl.java 7KB
UserServiceImpl.java 6KB
ProviderDaoImpl.java 6KB
ProviderServiceImpl.java 4KB
BillServiceImpl.java 4KB
BaseDao.java 3KB
LoginServlet.java 2KB
PageSupport.java 2KB
RoleDaoImpl.java 1KB
UserDao.java 1KB
RoleServiceImpl.java 1KB
User.java 1KB
UserService.java 1KB
SysFilter.java 1KB
共 263 条
- 1
- 2
- 3
资源评论
Traversal-chen
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 考研冲刺的实用经验与技巧.pptx
- golang语法和学习笔记
- YOLO 格式的带标签的口罩/不戴口罩的面部和人群图像
- 全国2000+个气象站点日尺度资料-【1961-2022年】-平均气温+最高气温+最低气温+降水
- 带有边界框的农作物和杂草检测数据 带有 YOLO 和 Pascal 标签的芝麻作物和不同杂草的农业数据
- 练习 JavaScript 的禅宗练习.zip
- 大学生Java二级课程考试
- Nvidia GeForce GT 1030-GeForce Game Ready For Win10&Win11(Win10&Win11 GeForce GT 1030显卡驱动)
- IEC61850仿真模拟器sim860
- 纯 Python Java 解析器和工具.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功