• 【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;
        }

  • 相关阅读:
    一个php soap的错误记录
    Android 开发有哪些新技术出现?
    每个PHP开发者都应该看的书
    30 个 PHP 的 Excel 处理类
    PHP Session可能会引起并发问题
    PHP代码优化技巧大盘点
    分析和解析PHP代码的7大工具
    关于 PHP 7 你必须知道的五件事
    PHP也20岁了
    PHP高级特性二之文件处理
  • 原文地址:https://www.cnblogs.com/cckong/p/14209383.html
Copyright © 2020-2023  润新知