Cookie和session

php apc缓存以及与redis的对比 APC简介 APC的全称为Alternative PHP Cache, 是一款开源的php插件,用来对php的代码或者用户数据进行缓存。 APC 对php代码的缓存 apc可以去掉php动态解析以及编译的时间,php脚本可以执行的更快。下面这张图很好的说明了为什么了apc可以让php脚本运行得更快。 PHP是一个动态脚本语言,所以为了让用户在浏览器中 阅读详情

会话?

什么是会话?
比如你打开一个浏览器,在浏览器中做了很多的事情,使用完之后关闭浏览器。
而这个过程我们叫做一次会话。
有状态会话:
比如你去商场办了一个会员,你怎么向商场证明你是这个商场的会员呢?
你------------>商场 出示会员卡
商场--------->你 在他们的会员系统中查

上面的是现实中的例子,下面我们举个网路中的例子。我们将你比作客户端,将商场比作服务端。

  • 服务端会给客户端发一个证件,下次来的时候带上这个证件就可以了,这个证件就是cookie
  • 服务端会登记客户端的信息,下次来的时候直接匹配就可以了。

保存会话的两种技术

  • Cookie
    客户端技术,主要是对响应和请求

  • Session
    服务端技术,利用这个技术可以保存用户的会话信息。

常见的案例有,目前大部分网站登录功能,比如bilibili,你已经登录过了,则你到bilibili的任何一个页面都不需要重新登录。

Cookie

package com.mrli.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

public class CookieServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码,解决乱码
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        //响应输出流
        PrintWriter out = resp.getWriter();

        //从请求中获得Cookie,但是Cookie不一定只有一个,所以是一个数组
        Cookie[] cookies = req.getCookies();

        //判断Cookie是否存在
        if(cookies!=null){
            //如果存在,遍历Cookie数组,如果有我们想要的cookie则获取到,然后响应给客户端
            for (Cookie cookie : cookies) {
                if(cookie.getName().equals("lastLocalTime")){//getName(),拿到Cookie的key
                    long lastLocalTime = Long.parseLong(cookie.getValue());//将时间戳变成一个长整型
                    Date date = new Date(lastLocalTime);//从字符串中解析一个时间

                    out.write("您上一次访问的时间是:"+date.toString());//将时间写入到响应对象
                }
            }
        }else{
            //如果Cookie不存在
            out.write("您是第一次访问本站");
        }

        //如果有Cookie则更新,没有则添加
        Cookie cookie = new Cookie("lastLocalTime", System.currentTimeMillis() + "");
        cookie.setMaxAge(60*60*24);//设置cookie的有限期,以分钟为单位
        resp.addCookie(cookie);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

Cookie的上限

  • 一个Cookie只能保存一个信息,键值对
  • 一个网站最多向浏览器发送20个Cookie,浏览器最多存300个Cookie
  • 一个Cookie大小限制为4kb

删除Cookie

  • 将有效期设置为0
  • 不设置有限期,关闭浏览器自动失效

编码解码

URLEncoder.encode();//编码
URLDecoder.decode();//解码

Session

Session是什么?

Session被称为“会话控制”,服务器会为每一个用户(浏览器)创建一个Session对象,Session可以用来保存会话的信息。
只要不关闭浏览器,Session就会一直存在。

Session和Cookie的区别

Cookie是将信息保存在浏览器上。(可以保存多个)
Session是将信息保存在服务器上。(用于保存重要的信息,但是也不要过多,尽量减少服务器资源的额外占用)
Session对象是由服务端创建的。

利用Session保存信息

package com.mrli.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.io.PrintWriter;

public class SessionDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        PrintWriter out = resp.getWriter();

        HttpSession session = req.getSession();
        String sessionid = session.getId();
        session.setAttribute("mrli",new Person("mrli",19));
        if(session.isNew()){
            out.write("这个session是新创建的");
        }else{
            out.write("这个session已经在服务器上存在了,ID:"+sessionid);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

然后我们就可以通过别的网站直接去获取

req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");

PrintWriter out = resp.getWriter();

HttpSession session = req.getSession();

out.write(String.valueOf((Person)session.getAttribute("mrli")));

删除信息

session.removeAttribute("mrli");


注销Session

第一种方法

session.invalidate();

第二种方法
在web.xml中设置Session的失效时间,但是关闭浏览器还是会被注销

  <session-config>
<!--    设置Session的失效时间,以分钟为单位-->
    <session-timeout>15</session-timeout>
  </session-config>

在这里插入图片描述

游戏脚本开发避坑:Python调用OP模块实现阴阳师后台操作的5个关键点 本文深入探讨了使用Python调用OP模块开发《阴阳师》后台自动化脚本的5个核心避坑点。重点解析了窗口绑定、后台截图与图像识别、鼠标键盘模拟、脚本稳定性以及性能优化等关键环节的常见问题与实战解决方案,帮助开发者高效实现稳定的游戏后台挂机功能。 阅读详情

相关推荐

DataGridView添加新行时在单元格绑定下拉列表DataGridViewComboBoxCell

效果图如下 先在界面上添加DataGridView,添加字段no、type、param 在lord事件中新建一行 dataGridView1.Rows.Add(); 在RowsAdded事件中操作新建的行 private void dataGridView1_RowsAdded_1(object sender, DataGridViewRowsAddedEventArgs...

wuqinglaohao的博客 1986

在PHP中自定义session的存储方式

描述 在PHP中可以通过定义session_set_save_handler,将服务器session数据存储在不同的介质上,比如存储在文件里,apc或memcache缓存中,或存储在数据库里。可对统计在线人数,或踢除特定会员的登陆状态等等。 自定义session_set_save_handler,基本上就是使用自定义的读写方法覆盖了系统默认的session的读写方法,以实现对session的管

yagas的专栏 1万+

雷达气象学(8)——反射率因子图实战(强对流预警篇)

本文聚焦雷达反射率因子图在强对流预警中的实战应用,深入解析了柱状回波、有界弱回波区(BWER)、三体散射(TBSS)等关键回波结构特征,这些是识别超级单体风暴和大冰雹的核心“身份证”。文章强调从静态识别转向动态追踪与多源数据综合研判的思维转变,并提供了系统的实战分析流程与常见误区避坑指南,旨在提升对强对流天气的短临预警能力。

weixin_29213827的博客 485

php APC 造成的session无法保存bug及解决方法

APC对 php 脚本的加速效果是明显的,基本可以将 php-fpm 服务器负载能力提高到 2 倍,所以在生产环境中,需要尽可能使用 APC 来加速 php 脚本。   这是我通过web bench 压力测试得出的结论,而在生产环境中,使用 APC 之后,脚本的执行速度确实有提高 (可能达到10-20% )   生产环境中使用 ses...

老张的自言自语 193

The moving least square approximation(MLS).

移动最小二乘法, moving least square

fanglovel的博客 299

佳能C3025打印机扫描方法

佳能C3025彩色打印机扫描方法 步骤一、如果打印机处于休眠状态,可按图中标记的按钮唤醒打印机; 然后点击屏幕上的【扫描】 步骤二、扫描类型选择【文件】 步骤三、点击屏幕上的【地址簿】 步骤四、此时屏幕胡看到名字,如果看不到自己的名字,可往下滑动直到看到自己的名字,然后点击自己的名字,再点击右下角的【应用】 步骤五、点击【发送设置】,可看到文件格式为PDF,点击可以选择JPEG的图片格式。...

weixin_46019317的博客 2万+

什么是session?什么是cookie?session和cookie有什么区别?

这里是修真院前端小课堂,本篇分析的主题是 【什么是session?什么是cookie?session和cookie有什么区别?】 每篇分享文从 【背景介绍】【知识剖析】【常见问题】【解决方案】【编码实战】【扩展思考】【更多讨论】【参考文献】 八个方面深度解析前端知识/技能,本篇分享的是: 【什么是session?什么是cookie?session和cookie有什么区别?】 什么...

IT修真院:初学者转行到互联网的聚集地 3万+

智能体在车联网中的应用:第19天 智能体理论与初步实践 D30:阶段小结——在SUMO中使用TraCI控制预编程智能体

本文介绍了如何将强化学习从算法仿真迁移到交通系统实践,重点讲解了SUMO微观交通仿真平台与TraCI实时控制接口的架构。通过构建一个预编程驾驶智能体,演示了车辆从起点到目标点的导航控制。文章详细解析了TraCI的双向通信机制和事件驱动模型,对比了其与传统RL环境的差异,并提供了完整的Python实现框架,包括路网配置、车辆控制和基于向量场的导航逻辑。该实践为后续开发高级学习型交通智能体奠定了基础。

IT深耕十余载,大道之简 1478

Cookie 和 Session

Cookie 和 Session 文章目录Cookie 和 Session一、session二、Cookie和session的区别三、servlet中对Cookie和Session提供的封装 前言: 这篇帖子重点讲讲Cookie和Session之间的区别,以及作用,Cookie在http协议中就提到了他的定义,作用,小伙伴们可以跳转到 Http协议 这个页面看看Cookie的基本概念及作用。 前情回顾: 1、Cookie是浏览器提供的一种让程序员在本地存储数据的能力,让数据在客户端这边更持久化。 2、C

qq_54219272的博客 1万+

【ESP32】ESP32连接JY61P并通过WIFI发送给电脑

ESP32S连接JY61P并通过WIFI把姿态数据发送给电脑1.采用Arduino IDE编译器;需要安装ESP32的开发板管理器;2.电脑接受数据是基于python的;

Doudou_Nai的博客 1132

YOLOv8首发优化:遥感目标检测 | 专为低质量遥感图像设计的边缘 - 高斯聚合(EGA)模块,解决低空间分辨率、传感器噪声、目标模糊、低光照退化和部分遮挡等限制

一种轻量级网络,其创新性地整合了专为低质量遥感图像设计的边缘 - 高斯聚合(EGA)模块。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 492

session、cookie和token

特性CookieSessionJWT存储位置客户端(浏览器)服务器端客户端(通常存储在浏览器的localStorage、sessionStorage或cookie中)数据类型主要为字符串(可序列化复杂对象)任意数据类型JSON格式,包含Header、Payload和Signature大小限制一般不超过4KB(不同浏览器可能有所不同)无明显限制,但受服务器内存和配置影响取决于编码后的长度,但通常较小生命周期可设置过期时间,默认为浏览器关闭时失效。

m0_69777632的博客 1817

3. UFS 电气时钟、复位、信号和电源

当接收到用于从 HS-MODE 到 LS-MODE 转换的 DME_POWERMODE.ind 或用于从 HS-MODE 到 HIBERN8 转换的 DME_HIBERNATE_ENTER.ind 时,UFS 主机可以启动一个计时器。在整个 PA_INIT 过程中,不应门控参考时钟。如果 UFS 主机启动从 HS-MODE 到 LS-MODE 或 HIBERN8 的电源模式更改,则应确保在关闭参考时钟之前,至少已经经过了由 bRefClkGatingWaitTime 定义的最小时间间隔,见图 6.3。

qq_42238448的博客 1293

Cookie和Session的关系

一、共同之处: cookie和session都是用来跟踪浏览器用户身份的会话方式。 二、工作原理: 1.Cookie的工作原理 (1)浏览器端第一次发送请求到服务器端 (2)服务器端创建Cookie,该Cookie中包含用户的信息,然后将该Cookie发送到浏览器端 (3)浏览器端再次访问服务器端时会携带服务器端创建的Cookie (4)服务器端通过Cookie中携带的数据区分不同的用户 2.Session的工作原理 (1)浏览器端第一次发送请求到服务器端,服务器端创建一个Session,同时会创建一个特

weixin_44279264的博客 6591

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【JavaEE】Cookie 和 Session

Cookie 和 Session 详解。

2301_79765510的博客 1530

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

shiro 的session ,cookie 以及 session 和 cookie 的区别

在玩 spring boot 集成 shiro ,,,可是 发现 它的 session 和 cookie 把我搞得有点懵了。。。 首先 声明 session 和 cookie 的 区别,,,其实 session 和 cookie 是 一样的东西, **顺便提一下,,,在web项目里面 s...

chuncui2576的博客 2029

Session和Cookie

• 定义 :Session 是一种服务器端的机制,用于在服务器上存储用户的状态信息。它通过一个唯一的标识符(Session ID)来区分不同的用户会话。• 特点 :• 数据存储在服务器端。• Session ID 通常通过 Cookie 传递给客户端。• 适合存储敏感信息(如用户登录状态、购物车内容等)。• 生命周期由服务器控制,通常会设置超时时间。特性CookieSession存储位置客户端(浏览器)服务器端安全性较低,容易被窃取或篡改较高,数据存储在服务器端。

Aric_Jones的博客 1171

Cookie和session的区别

当然,伪造的时候需要注意,直接copy cookie文件到 cookie目录,浏览器是不认的,他有一个index.dat文件,存储了 cookie文件的建立时间,以及是否有修改,所以你必须先要有该网站的 cookie文件,并且要从保证时间上骗过浏览器。sessionid是服务器和客户端连接时候随机分配的,如果浏览器使用的是cookie,那么所有数据都保存在浏览器端,比如你登陆以后,服务器设置了cookie用户名,那么当你再次请求服务器的时候,浏览器会将用户名一块发送给服务器,这些变量有一定的特殊标记。

小蕊的博客 1万+

Cookie和Session

识别用户身份的两种技术:cookie和session。Cookie,类型为“小型文本文件”,是某些网站为了辨别用户身份,进行会话跟踪而存储在用户本地终端上的数据(通常会进行加密),由客户端计算机暂时或者永久保存的信息。session:在计算机中,尤其是在网络应用中,称为“会话控制”。Session 对象存储特定用户会话所需的属性及配置信息。

Reset 1212

Cookie和Session的区别和联系

Cookie和Session出现的原因:由于http 协议是无状态的,服务器无法确定这次请求和上次的请求是否来自同一个客户端。利用session和cookie可以让服务器知道不同的请求是否来自同一个客户端。 1、Cookie定义 Cookie是服务器在本地机器上存储的小段文本并随每一个请求发送至同一服务器。Cookies保存在客户端,主要内容包括:名字,值,过期时...

摸金校尉的博客 2万+

cookie和session

紧密协作:Cookie 和 Session 是协同工作的。Cookie 提供了一种机制,让客户端能够存储服务器分配的 Session ID,并在后续请求中自动发送回去。Session 则利用这个 ID 在服务器端存储和管理实际的用户状态数据。分工不同Cookie:主要负责在客户端和服务器之间传递Session ID,以及存储少量不敏感的、客户端可直接访问的数据(如用户偏好设置)。Session:主要负责在服务器端存储用户的敏感数据和复杂状态。安全性。

2402_83672777的博客 762

为什么要有cookie和session,以及cookie和session的区别

使用Cookie 1、创建一个新的Cookie          Cookie cookie = new Cookie("username",name); 2、设置cookie在客户端上存活多久          cookie.setMaxAge(30*60); 3、把cookie发送到客户          response.addCookie(cookie); 4、从客户请求得到

chenlili_liumiao的专栏 9324

session和cookie

cookie是直接将信息保存在cookie中,京东存储购物车中商品的cookie可能是这样的:productIds=xxxxx,yyyy,zzz,kkkk,当浏览器发送请求时,会携带相应的cookie,服务器解析出cookie中的内容,但是随着购物车内的商品越来越多,每次请求的 cookie 也越来越大,无法通过简单的 cookie 机制传递这么多信息,而且要知道 cookie 字段是存储在 HTTP header 中的,就算能够承载这些信息,也会消耗很多的带宽,比较消耗网络资源。cookie有什么用呢?

weixin_67950243的博客 1579
上一篇: JSP页面${pageContext.request.contextPath}出现乱码问题
下一篇: JSP使用
小小代码熊
博客等级 码龄7年 5粉丝 77原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值