• lhkfw123456
    了解作者
  • Java
    开发工具
  • 1.6MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 3
    下载次数
  • 2018-07-14 15:14
    上传日期
分别实现账单,供应商和用户三者的增删改查和分页查询
smbms.zip
内容介绍
package com.ww.smbms.servlet; import java.io.IOException; import java.io.PrintWriter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; 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 com.ww.smbms.pojo.User; import com.ww.smbms.service.UserService; import com.ww.smbms.service.impl.UserServiceImpl; @SuppressWarnings("serial") public class UserListServlet extends HttpServlet { /** * Constructor of the object. */ public UserListServlet() { super(); } /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String method = request.getParameter("method"); if(method!=null && method.equals("query")){ this.query(request, response); System.out.println("=====query()====="); }else if(method!=null && method.equals("add")){ this.add(request, response); System.out.println("=====add()====="); }else if(method!=null && method.equals("ucexist")){ this.userCodeExist(request, response); System.out.println("=====userCodeExist()====="); }else if(method!=null && method.equals("deleteUser")){ this.deleteUser(request, response); }else if(method!=null && method.equals("view")){ System.out.println("=====view======="); this.getUser(request, response,"jsp/userView.jsp"); }else if(method!=null && method.equals("modify")){ this.getUser(request, response,"jsp/userUpdate.jsp"); }else if(method!=null && method.equals("update")){ this.updateUser(request, response); }else if(method!=null && method.equals("checkPwd")){ System.out.println("=====checkPwd====="); this.chechPwd(request, response); }else if(method!=null && method.equals("updatePwd")){ this.updatePwd(request, response); } } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } public void query(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userName = request.getParameter("userName"); if(userName==null){//防止Null注入 userName=""; } List<User> userList = null; UserService userService = new UserServiceImpl(); userList = userService.getUserList(userName); request.setAttribute("userList", userList); request.getRequestDispatcher("jsp/userList.jsp").forward(request, response); } public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { User user = new User(); user.setUserCode(request.getParameter("userCode")); user.setUserName(request.getParameter("userName")); user.setUserPassword(request.getParameter("userPassword")); user.setGender(Integer.valueOf(request.getParameter("gender"))); try { user.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("birthday"))); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } user.setPhone(request.getParameter("phone")); user.setAddress(request.getParameter("address")); user.setUserType(Integer.valueOf(request.getParameter("userType"))); user.setCreatedBy((Integer)(request.getSession().getAttribute("id")) ); user.setCreationDate(new Date()); UserService userService = new UserServiceImpl(); boolean isAdd = userService.addUser(user); if(isAdd){ request.getRequestDispatcher("/userList.do?method=query&userName=").forward(request, response); }else{ response.sendRedirect("jsp/userAdd.jsp"); } } public 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", "null"); }else{ UserService userService = new UserServiceImpl(); User user = userService.selectUserCodeExist(userCode); if(user!=null){ resultMap.put("userCode", "exist"); }else{ resultMap.put("userCode", "notExist"); } } //把resultMap转为json字符串输出 response.setContentType("application/json");//配置上下文的输出类型 //从response对象中获取输出的witer对象 PrintWriter out = response.getWriter(); //输出resultMap转换为json字符串 out.write(JSONArray.toJSONString(resultMap)); out.flush();//刷新 out.close();//关闭流 } private void deleteUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userId = request.getParameter("userid"); int id =0; try{ id = Integer.valueOf(userId); }catch (Exception e) { // TODO: handle exception e.printStackTrace(); id=0; } HashMap<String, String> map = new HashMap<String, String>(); if(id>0){ UserService userService = new UserServiceImpl(); User user = new User(); user.setId(id); boolean isDelete = userService.deleteUser(user); if(isDelete){ map.put("delResult", "OK"); }else{ map.put("delResult", "ERROR"); } }else{ map.put("delResult", "NOTEXIST"); } response.setContentType("application/json"); PrintWriter out = response.getWriter(); out.print(JSONArray.toJSON(map)); out.flush(); out.close(); } private void getUser(HttpServletRequest request, HttpServletResponse response,String url) throws ServletException, IOException { String userId = request.getParameter("userid"); System.out.println("userId="+userId); int id=0; try{ id = Integer.valueOf(userId); }catch (Exception e) { // TODO: handle exception id=0; } if(id>0){ UserService userService = new UserServiceImpl(); User user = userService.getUser(id); request.setAttribute("user", user); request.getRequestDispatcher(url).forward(request, response); }else{ response.sendRedirect("jsp/userList.jsp"); } } private void updateUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { User user = new User(); user.setId(Integer.valueOf(request.getParameter("id"))); user.setUserName(request.getParameter("userName")); user.setGender(Integer.valueOf(request.getParameter("gender"))); try { user.setBirthday(new SimpleDateFormat("yyyy-MM-dd")
评论
    相关推荐
    • smbms.zip
      实现了超市管理系统,基于SSM的框架,里面也包含了初始化的SQL文件
    • 超市管理系统原型-new.rar
      smbms原型,包含数据库代码以及前端jsp代码
    • 超市账单管理系统》项目素材.rar
      超市账单素材,用于2单元学习的项目题目超市账单素材,用于提高学习基础,作为学习基础的必要课程
    • 超市订单管理系统.zip
      管理员的登录以及对商品、用户供应商信息的增删改查
    • 超市管理系统
      超市管理系统: 1.数据库设计: smbms_user 超市的工作人员 每个工作人员都有角色 smbms_role 人员的角色 3种: 系统管理员: 经理 : 普通员工: smbms_bill 超市账单 账单属于某个供应商 smbms_...
    • 贯穿案例:超市订单管理系统.rar
      系统主要有订单管理供应商管理用户管理等模块组成,系统采用javabean+servlet+jsp开发 运行环境:jdk7+tomcat7+mysql+(eclipse)IntelliJ IDEA+maven 项目技术:javabean+servlet+jsp+jquery
    • 超市订单管理系统.zip
      各位同志好,超市订单管理系统是一个本人曾经做过的一个javaweb项目,这个项目基于mybatis数据访问框架,spring 以及springMVC 这两个框架,代码注释清晰,并且附带赠送配套数据库一个,很适合初学SSM框架的同学拿来...
    • 超市管理系统SSM
      完整的超市管理系统web项目,内带数据库文件,导入即可使用 完整的超市管理系统web项目,内带数据库文件,导入即可使用 完整的超市管理系统web项目,内带数据库文件,导入即可使用
    • 超市账单管理系统的源码和其他文档.zip
      超市账单管理系统的项目立项需求分析源码代码设计与实现,系统设计说明书以及数据库sql文件
    • BBS_system_on_java.rar
      BBS论坛系统由JAVA和JSP实现,开发中涉及JavaBean,JSP和服务器Tomcat5.0.7的设置,数据库用SQL2000。有注册登陆,浏览,发帖 回帖,帖子管理,论坛设置,管理版块,用户管理等模块。