• 【smbms】密码修改流程


    (servlet)

    //实现servlet复用
    public class UserServlet extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            //从session获取id
            Object o=req.getSession().getAttribute(Constants.USER_SESSION);
    
            String newpassword=req.getParameter("newpassword");
            boolean flag=false;
            System.out.println("newpassword1"+newpassword);
            if(o!=null&&!StringUtils.isNullOrEmpty(newpassword))
            {
                UserService userService=new UserServiceImp1();
    
                flag=userService.updatePwd(((User)o).getId(),newpassword);
    
                if(flag)
                {
                    System.out.println("newpassword flag"+newpassword);
                    req.setAttribute("message","修改密码成功 请重新登录");
                    //修改完密码 移除session
                    req.getSession().removeAttribute(Constants.USER_SESSION);
    
                }
                else
                {
                    req.setAttribute("message","修改密码失败");
                 }
            }
            else
            {
                req.setAttribute("message","新密码有问题");
    
    
            }
            req.getRequestDispatcher("pwdmodify.jsp").forward(req,resp);
        }

    (service)

      public boolean updatePwd(int id, String password) {
            Connection connection=null;
            boolean flag=false;
            System.out.println("newpassword service"+password);
            try {
                connection=BaseDao.getConnection();
                if(userDao.updatePwd(connection,id,password)>0)
                {
                    flag=true;
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            finally {
                BaseDao.closeResource(connection,null,null);
            }
            return flag;
        }

    (dao)

     public int updatePwd(Connection connection, int id, String password) {
            PreparedStatement pstm=null;
            //execute执行了几行的改动
            int execute=0;
            if(connection!=null)
            {
                String sql="update smbms_user set userPassword = ? where id =?";
                Object params[]={password,id};
                System.out.println("newpassword dao"+password);
                try {
                    execute=BaseDao.execute(connection,sql,params,pstm);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                BaseDao.closeResource(null,pstm,null);
            }
    
            return execute;
        }

  • 相关阅读:
    Jzoj4822 完美标号
    Jzoj4822 完美标号
    Jzoj4792 整除
    Jzoj4792 整除
    Educational Codeforces Round 79 A. New Year Garland
    Good Bye 2019 C. Make Good
    ?Good Bye 2019 B. Interesting Subarray
    Good Bye 2019 A. Card Game
    力扣算法题—088扰乱字符串【二叉树】
    力扣算法题—086分隔链表
  • 原文地址:https://www.cnblogs.com/cckong/p/14209383.html
Copyright © 2020-2023  润新知