//保存cookie

Cookie cookieName = new Cookie("name", realUser.getName());
                Cookie cookiePwd = new Cookie("pwd", realUser.getPwd());
                Cookie cookieId = new Cookie("id", realUser.getId()+"");
                int time = 60*60*24*7;
                cookieId.setMaxAge(time);
                cookieName.setMaxAge(time);
                cookieId.setMaxAge(time);
                response.addCookie(cookieName);
                response.addCookie(cookiePwd);

response.addCookie(cookieId);

 
 
 
//jsp 中读取cookie
 
 
<%
    Cookie cookie[] = request.getCookies();
    if (cookie != null) {
        
        for (int i = 0; i < cookie.length; i++) {
            System.out.println(cookie[i].getValue());
            Cookie c = cookie[i];
            if (c.getValue().equals("admin")) {//查找cookie里面的是否存在cookie键位c_name的cookie
                //如果存在该键 取该键对应的值==>相当于Map取值
                response.sendRedirect("hello.jsp");
            }
        }
    }

%>

Cookie 用法 小记的更多相关文章

  1. [转]HttpClient的超时用法小记

    HttpClient的超时用法小记 HttpClient在使用中有两个超时时间,是一直接触和使用的,由于上次工作中使用httpClient造成了系统悲剧的情况,特地对它的两个超时时间进行了小小的测试, ...

  2. jquery cookie 用法

    jquery cookie 用法 $.cookie("name","value","options")  当不设置options时,此coo ...

  3. Matlab norm 用法小记

    Matlab norm 用法小记 matlab norm (a) 用法以及实例 norm(A,p)当A是向量时norm(A,p)   Returns sum(abs(A).^p)^(1/p), for ...

  4. jquery.cookie用法详细解析,封装的操作cookie的库有jquery.cookie.js

    jquery.cookie用法详细解析 需要注意存入cookie前,对数据进行序列化, 得到后在反序列化: 熟练运用:JSON.stringify();和JSON.parse(): 通常分为如下几个步 ...

  5. linux expect, spawn用法小记

    linux expect, spawn用法小记_IT民工_百度空间 linux expect, spawn用法小记 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://sys ...

  6. [转载]expect spawn、linux expect 用法小记

    原文地址:expect spawn.linux expect 用法小记作者:悟世 使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明,初学者一般都是照抄.收藏.可是为什么要这么写 ...

  7. Shell常见用法小记

    shell的简单使用 最近发现shell脚本在平常工作中简直算一把瑞士军刀,很多场景下用shell脚本能实现常用的简单需求,而之前都没怎么学习过shell,就趁机把shell相关的语法和常见用法总结了 ...

  8. golang 的 http cookie 用法

    golang的http cookie用法 在服务端程序开发的过程中,cookie经常被用于验证用户登录.golang 的 net/http 包中自带 http cookie的定义,下面就来讲一下coo ...

  9. jquery cookie用法

    jquery cookie用法(获取cookie值,删除cookie) cookie在jquery中有指定的cookie操作类,下面我先来介绍我们在使用cookie操作类时的一些问题,然后介绍正确的使 ...

随机推荐

  1. 【译文】JNI编程

    原文链接: https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html   没有逐字翻译,解说了文章的大 ...

  2. tomcat server.xml中文版

    原文:http://www.blogjava.net/baoyaer/articles/107278.html Tomcat Server的结构图 该文件描述了如何启动Tomcat Server &l ...

  3. vue2/vuex2的那点坑

    说是坑,其实大部分是我们自己的过错! vuex官方demo在1.0可以运行,在2.0报错?此类问题,应该很常见吧? 还有顺溜的利用1.0搭建的webpack编译环境到了vue2.0突然失效了,报错了? ...

  4. 解决 release-stripped.ap_' specified for property 'resourceFile' does not exist.

    设置buildTypes里的release的shrinkResources为false即可,如果是 release-stripped.ap_' specified for property 'reso ...

  5. Java中的24种设计模式与7大原则

    一.创建型模式 1.抽象工厂模式(Abstract factory pattern): 提供一个接口, 用于创建相关或依赖对象的家族, 而不需要指定具体类.2.生成器模式(Builder patter ...

  6. WebForm控件--2016年12月29日

    简单控件 1.Label  =>   <span id="Label1">Label1</span> 2.Literal  =>  Text 填 ...

  7. XCode8目录整理后的几个警告消除,Missing file

    Git目录没有及时更新导致 终端进入目录运行如下命令 git rm main.m git rm Info.plist git rm AppDelegate.h git rm AppDelegate.m ...

  8. Git 修改源地址

    git remote set-url origin http://git.xxx.com/xxx/repo.git

  9. VS Build目录下各文件的作用

    VS2010中各种类型文件的作用: .sln 相当于VC6中 .dsw    .vcxproj 相当于VC6中 .dsp    .suo 相当于VC6中 .ncb    .vcxproj.filter ...

  10. Mybatis批量操作

    首先,mysql需要数据库连接配置&allowMultiQueries=true jdbc:mysql://127.0.0.1:3306/mybank?useUnicode=true& ...