package cn.smbms.servlet.user;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Array;
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;
import com.alibaba.fastjson.JSONArray;
import com.mysql.jdbc.StringUtils;
import cn.smbms.pojo.Role;
import cn.smbms.pojo.User;
import cn.smbms.service.role.RoleService;
import cn.smbms.service.role.RoleServiceImpl;
import cn.smbms.service.user.UserService;
import cn.smbms.service.user.UserServiceImpl;
import cn.smbms.tools.Constants;
import cn.smbms.tools.PageSupport;
import com.sun.xml.internal.bind.v2.model.core.ID;
public class UserServlet extends HttpServlet {
public UserServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String method = request.getParameter("method");
System.out.println("method----> " + method);
if(method != null && method.equals("add")){
//增加操作
this.add(request, response);
}else if(method != null && method.equals("query")){
this.query(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);
}else if(method != null && method.equals("pwdmodify")){
this.getPwdByUserId(request, response);
}else if(method != null && method.equals("savepwd")){
this.updatePwd(request, response);
}
}
private void updatePwd(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Object o = request.getSession().getAttribute(Constants.USER_SESSION);
String newpassword = request.getParameter("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, "修改密码成功,请退出并使用新密码重新登录!");
request.getSession().removeAttribute(Constants.USER_SESSION);//session注销
}else{
request.setAttribute(Constants.SYS_MESSAGE, "修改密码失败!");
}
}else{
request.setAttribute(Constants.SYS_MESSAGE, "修改密码失败!");
}
request.getRequestDispatcher("pwdmodify.jsp").forward(request, response);
}
private void getPwdByUserId(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Object o = request.getSession().getAttribute(Constants.USER_SESSION);
String oldpassword = request.getParameter("oldpassword");
Map<String, String> resultMap = new HashMap<String, String>();
if(null == o ){//session过期
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");
}
}
response.setContentType("application/json");
PrintWriter outPrintWriter = response.getWriter();
outPrintWriter.write(JSONArray.toJSONString(resultMap));
outPrintWriter.flush();
outPrintWriter.close();
}
private void modify(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id = request.getParameter("uid");
String userName = request.getParameter("userName");
String gender = request.getParameter("gender");
String birthday = request.getParameter("birthday");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
String userRole = request.getParameter("userRole");
User user = new User();
user.setId(Integer.valueOf(id));
user.setUserName(userName);
user.setGender(Integer.valueOf(gender));
try {
user.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse(birthday));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
user.setPhone(phone);
user.setAddress(address);
user.setUserRole(Integer.valueOf(userRole));
user.setModifyBy(((User)request.getSession().getAttribute(Constants.USER_SESSION)).getId());
user.setModifyDate(new Date());
UserService userService = new UserServiceImpl();
if(userService.modify(user)){
response.sendRedirect(request.getContextPath()+"/jsp/user.do?method=query");
}else{
request.getRequestDispatcher("usermodify.jsp").forward(request, response);
}
}
private void getUserById(HttpServletRequest request, HttpServletResponse response,String url)
throws ServletException, IOException {
String id = request.getParameter("uid");
if(!StringUtils.isNullOrEmpty(id)){
//调用后台方法得到user对象
UserService userService = new UserServiceImpl();
User user = userService.getUserById(id);
request.setAttribute("user", user);
request.getRequestDispatcher(url).forward(request, response);
}
}
private void delUser(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id = request.getParameter("uid");
Integer delId = 0;
try{
delId = Integer.parseInt(id);
}catch (Exception e) {
// TODO: handle exception
delId = 0;
}
HashMap<String, String> resultMap = new HashMap<String, String>();
if(delId <= 0){
resultMap.put("delResult", "notexist");
}else{
UserService userService = new UserServiceImpl();
if(userService.deleteUserById(delId)){
resultMap.put("delResult", "true");
}else{
resultMap.put("delResult", "false");
}
}
//把resultMap转换成json对象输出
response.setContentType("application/json");
PrintWriter outPrintWriter = response.getWriter();
outPrintWriter.write(JSONArray.toJSONString(resultMap));
outPrintWriter.flush();
outPrintWriter.close();
}
private void userCodeExist(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//判断用户账号是否可用
String userCode = request.getParameter("userCode");
HashMap<String, String> resultMap = new HashMap<String, String>();
if(StringUtils.isNullOrEmpty(userCode)){
//userCode == null || userCode.equals("")
resultMap.put("userCode", "exist");
}else{
UserService userService = new UserServiceImpl();
User user = userService.selectUserCodeExist(userCode);
if(null != user){
resultMap.put("userCode","exist");
}else{
resultMap.put("userCode", "notexist");
}
}
//把resultMap转为json字符串以json的形式输出
//配置上下文的输出类型
response.setContentType("application/json");
//从response对象中获取往外输出的writer对象
PrintWriter outPrintWriter = response.getWriter();
//把resultMap转为json字符串 输出
outPrintWriter.write(JSONArray.toJSONString(resultMap));
outPrintWriter.flush();//刷新
outPrintWriter.close();//关闭流
}
private void getRoleList(HttpServletRequest request, HttpServletRes
没有合适的资源?快使用搜索试试~ 我知道了~
基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip
共507个文件
class:132个
jar:72个
js:69个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 143 浏览量
2024-01-11
10:12:02
上传
评论
收藏 29.9MB ZIP 举报
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip 基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip 基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip 基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip 基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip 基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip 基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip 基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于Jsp+Tomcat+Servlet+Filter的超市管理系统源码+数据库.zip (507个子文件)
UserServlet.class 11KB
UserServlet.class 11KB
UserServlet.class 11KB
UserServlet.class 11KB
BillServlet.class 8KB
BillServlet.class 8KB
BillServlet.class 8KB
BillServlet.class 8KB
UserDaoImpl.class 8KB
UserDaoImpl.class 8KB
UserDaoImpl.class 8KB
UserDaoImpl.class 8KB
BillDaoImpl.class 7KB
BillDaoImpl.class 7KB
BillDaoImpl.class 7KB
BillDaoImpl.class 7KB
ProviderServlet.class 7KB
ProviderServlet.class 7KB
ProviderServlet.class 7KB
ProviderServlet.class 7KB
ProviderDaoImpl.class 6KB
ProviderDaoImpl.class 6KB
ProviderDaoImpl.class 6KB
ProviderDaoImpl.class 6KB
UserServiceImpl.class 6KB
UserServiceImpl.class 6KB
UserServiceImpl.class 6KB
UserServiceImpl.class 6KB
ProviderServiceImpl.class 4KB
ProviderServiceImpl.class 4KB
ProviderServiceImpl.class 4KB
ProviderServiceImpl.class 4KB
BillServiceImpl.class 4KB
BillServiceImpl.class 4KB
BillServiceImpl.class 4KB
BillServiceImpl.class 4KB
User.class 3KB
User.class 3KB
User.class 3KB
User.class 3KB
BaseDao.class 3KB
BaseDao.class 3KB
BaseDao.class 3KB
BaseDao.class 3KB
Bill.class 3KB
Bill.class 3KB
Bill.class 3KB
Bill.class 3KB
BigDecimalUtil.class 3KB
BigDecimalUtil.class 3KB
BigDecimalUtil.class 3KB
BigDecimalUtil.class 3KB
Provider.class 3KB
Provider.class 3KB
Provider.class 3KB
Provider.class 3KB
LoginServlet.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
RoleDaoImpl.class 2KB
RoleDaoImpl.class 2KB
RoleDaoImpl.class 2KB
RoleDaoImpl.class 2KB
SysFilter.class 2KB
SysFilter.class 2KB
SysFilter.class 2KB
SysFilter.class 2KB
Role.class 2KB
Role.class 2KB
Role.class 2KB
Role.class 2KB
LogoutServlet.class 2KB
LogoutServlet.class 2KB
LogoutServlet.class 1KB
LogoutServlet.class 1KB
PageSupport.class 1KB
PageSupport.class 1KB
PageSupport.class 1KB
PageSupport.class 1KB
RoleServiceImpl.class 1KB
RoleServiceImpl.class 1KB
RoleServiceImpl.class 1KB
RoleServiceImpl.class 1KB
BigDecimalUtil$BigDecimalOprations.class 1KB
BigDecimalUtil$BigDecimalOprations.class 1KB
BigDecimalUtil$BigDecimalOprations.class 1KB
BigDecimalUtil$BigDecimalOprations.class 1KB
CharacterEncoding.class 1KB
CharacterEncoding.class 1KB
CharacterEncoding.class 1KB
CharacterEncoding.class 1KB
BigDecimalUtil$1.class 914B
BigDecimalUtil$1.class 914B
BigDecimalUtil$1.class 914B
BigDecimalUtil$1.class 914B
UserDao.class 814B
UserDao.class 814B
UserDao.class 814B
UserDao.class 814B
共 507 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
土豆片片
- 粉丝: 1841
- 资源: 5690
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 本资源库是关于“Java Collection Framework API”的参考资料,是 Java 开发社区的重要贡献,旨在提供有关 Java 语言学院 API 的实践示例和递归教育关系 .zip
- 插件: e2eFood.dll
- 打造最强的Java安全研究与安全开发面试题库,帮助师傅们找到满意的工作.zip
- (源码)基于Spark的实时用户行为分析系统.zip
- (源码)基于Spring Boot和Vue的个人博客后台管理系统.zip
- 将流行的 ruby faker gem 引入 Java.zip
- (源码)基于C#和ArcGIS Engine的房屋管理系统.zip
- (源码)基于C语言的Haribote操作系统项目.zip
- (源码)基于Spring Boot框架的秒杀系统.zip
- (源码)基于Qt框架的待办事项管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功