zoukankan      html  css  js  c++  java
  • 后台取浏览器中cookie的用法

    private static View gsonView(String attributeName) {
            return gsonView(attributeName, null);
    }
    public static final String UTF8 = "UTF-8";
    @RequestMapping(value = "/example01")
        public View example01(String cellNum, String passwd, Model model, HttpServletRequest request) {
            // Cookie取出用户名,查询此用户的相关信息
            String username = "";
            Cookie[] cookies = request.getCookies();// 前端通过Ajax映射该.do方法,这样便可以获取浏览器传过来的cookie信息
            String key = "";
            String value = "";
            for (Cookie cookie : cookies) {
                try {
                    key = URLDecoder.decode(cookie.getName(), UTF8);
                } catch (UnsupportedEncodingException e) {
                    LOG.error(e.getMessage());
                }
                try {
                    value = URLDecoder.decode(cookie.getValue(), UTF8);
                } catch (UnsupportedEncodingException e) {
                    LOG.error(e.getMessage());
                }
                if (key.equalsIgnoreCase(LOGONUSERIDLASTTIME)) {
                    username = value;
                    break;   //获取到想要的信息后,break此for循环
                }
            }
    
            long id = sendSafeCmdOpt.getNextHistoryId();//取下一个id,此id通过创建数据库sequence生成递增的id
            long iD = 3000000000L + id;
            sendSafeCmdOpt.cellAlarm(username, iD, cellNum, passwd);
            boolean result = true;
            String attributeName = "cellAlarm";
            model.addAttribute(attributeName, result);//返回true,告诉前端Ajax,后台方法调用成功。
            return gsonView(attributeName);//以gson方式返回true
        }
  • 相关阅读:
    LintCode-35.翻转链表
    LintCode-159.寻找旋转排序数组中的最小值
    LintCode-73.前序遍历和中序遍历树构造二叉树
    LintCode-9.Fizz Buzz 问题
    NOI 2018 归程 (Kruskal重构树)
    模板 NTT 快速数论变换
    模板 FFT 快速傅里叶变换
    BZOJ 3510 首都 (LCT)
    BZOJ 4530 [BJOI2014]大融合 (LCT)
    BZOJ 3282 Link Cut Tree (LCT)
  • 原文地址:https://www.cnblogs.com/enshrineZither/p/2855874.html
Copyright © 2011-2022 走看看