超市订单管理系统SMBMS - ajax验证旧密码功能实现

超市订单管理系统SMBMS - ajax验证旧密码功能实现,第1张

超市订单管理系统SMBMS - ajax验证旧密码功能实现 使用Ajax优化密码登录 导入阿里巴巴的fastjson

    com.alibaba
    fastjson
    1.2.78


设置session过期时间
    
        30
    
后台代码修改
 //验证旧密码,session中有用户的密码
    public void pwdmodify(HttpServletRequest req, HttpServletResponse resp){
        //从session里面拿ID;
        Object o = req.getSession().getAttribute(Constants.USER_SESSION);
        String oldpassword = req.getParameter("oldpassword");
        //万能的map
        HashMap resultMap = new HashMap();
        if (o==null){//session失效了,session过期了
            resultMap.put("result","sessionerror");
        }else if(StringUtils.isNullOrEmpty(oldpassword)){//输入密码为空
            resultMap.put("result","error");
        }else {
            String userPassword = ((User) o).getUserPassword();//session中用户的密码
            if (oldpassword.equals(userPassword)){
                resultMap.put("result","true");
            }else{
                resultMap.put("result","false");
            }
        }
        resp.setContentType("application/json");
        try {
            PrintWriter writer = resp.getWriter();
            //JSONAray阿里巴巴的工具类,转换格式
            
            writer.write(JSONArray.toJSONString(resultMap));
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5722498.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存