Session is used to save the message for the hole period of user dialogue in web service.Such as the message of user login.

In computer science, in particular networking, a session is a semi-permanent interactive information interchange, also known as a dialogue, a conversation or a meeting, between two or more communicating devices, or between a computer and user (see Login session). A session is set up or established at a certain point in time, and then torn down at some later point. An established communication session may involve more than one message in each direction. A session is typically, but not always, stateful, meaning that at least one of the communicating parts needs to save information about the session history in order to be able to communicate, as opposed to stateless communication, where the communication consists of independent requests with responses.

--------------  From Wikipedia

    public String login(String username, String captchaId,
String captcha, Long storeId, HttpSession session,HttpServletRequest request)
{
String enPassword = rsaService.decryptParameter("enPassword", request);
rsaService.removePrivateKey(request); if (!captchaService.isValid(CaptchaType.storeUserLogin, captchaId,
captcha))
{
return AjaxMsg.failed("验证码错误");
} if (Utils.isEmpty(username) || Utils.isEmpty(enPassword))
{
return AjaxMsg.failed("用户名或密码不能为空");
} if(!Utils.isPositiveLong(storeId))
{
return AjaxMsg.failed("storeId不能为空");
} List<Filter> filters = new ArrayList<Filter>();
Filter filter = new Filter("username", Filter.Operator.eq, username);
filters.add(filter); List<StoreUser> storeUsers = storeUserService.findList(null, filters,
null); if (Utils.isEmpty(storeUsers))
{
return AjaxMsg.failed("用户不存在");
} StoreUser storeUser = storeUsers.get(0); if(!storeId.equals(storeUser.getStoreShop().getId()))
{
return AjaxMsg.failed("用户不存在");
} if (!storeUser.getEnabled())
{
return AjaxMsg.failed("该用户未启用");
} if (!DigestUtils.md5Hex(enPassword).equals(storeUser.getPassword()))
{
return AjaxMsg.failed("用户名和密码不匹配");
} session.setAttribute(StoreUser.PRINCIPAL_ATTRIBUTE_NAME, new Principal(storeUser.getId(), storeUser.getUsername())); return AjaxMsg.success(storeUser.getIsManager()+"");
}

Differences between cookie and session:

Cookie can only save the value of ASCII string.But session can even save the value of java bean.We can take session as a java container.

Cookie is saved in web browser.So it's not safe.Session is saved in server.

We can set cookie's "period of validity" as long as we want.But can't this so for session.

Session is a burden of server.

cookie and session的更多相关文章

  1. Cookie和Session的总结

    1.开篇 在之前学习这一段的时候我一直有点没弄清楚,其实对Session这块的理解还可以,但是Cookie感觉始终还是欠缺点火候.之后的很长一段时间都基本上很少用Cookie了,渐渐的也淡忘了这一块的 ...

  2. java的会话管理:Cookie和Session

    java的会话管理:Cookie和Session 1.什么是会话 此处的是指客户端(浏览器)和服务端之间的数据传输.例如用户登录,购物车等 会话管理就是管理浏览器客户端和服务端之间会话过程产生的会话数 ...

  3. Cookie和Session的那些事儿

    Cookie和Session都是为了保持用户的访问状态,一方面为了方便业务实现,另一方面为了简化服务端的程序设计,提高访问性能.Cookie是客户端(也就是浏览器端)的技术,设置了Cookie之后,每 ...

  4. django的cookie和session以及内置信号、缓存

    cookie和session cookie和session的作用: cookie和session都记录了客户端的某种状态,用来跟踪用户访问网站的整个回话.两者最大的区别是cookie的信息是存放在浏览 ...

  5. Cookie和Session的区别

    前言 HTTP是一种无状态的协议,为了分辨链接是谁发起的,就需要我们自己去解决这个问题.不然有些情况下即使是同一个网站我们每打开一个页面也都要登录一下.而Session和Cookie就是为解决这个问题 ...

  6. 本地数据Store。Cookie,Session,Cache的理解。Timer类主要用于定时性、周期性任务 的触发。刷新Store,Panel

    本地数据Store var monthStore = Ext.create('Ext.data.Store', { storeId : 'monthStore', autoLoad : false, ...

  7. Cookie与Session

    再说Cookie与Session之前,先要了解一下http协议. 何为http协议: http协议即超文本传输协议,一种基于浏览器请求与服务器响应的协议,该协议主要的特点就是它是一种无状态的协议(只针 ...

  8. 【转】Cookie和Session区别和联系详解

    会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...

  9. 理解Cookie和Session机制(转)

    目录[-] Cookie机制 什么是Cookie 记录用户访问次数 Cookie的不可跨域名性 Unicode编码:保存中文 BASE64编码:保存二进制图片 设置Cookie的所有属性 Cookie ...

  10. cookie 和session 的区别详解

    这些都是基础知识,不过有必要做深入了解.先简单介绍一下. 二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cookie 会帮你在网站上所打的文字或是一些选择, 都纪 ...

随机推荐

  1. C/ C++ 常见编程问题

    C 中容易忽略的问题 1.在C语言中,浮点型变量分为两类: a. 单精度型:类型说明符为float, 在Turbo C 中占4个字节(32位)内存空间,其数值范围为3.4E-38~3.4E+38,可提 ...

  2. Sql 邮件发送

    select name from msdb.dbo.sysmail_profile --邮件发送日志 SELECT * FROM msdb.dbo.sysmail_event_log delete F ...

  3. linux crontab命令参数及用法详解--linux自动化定时任务cron

    声明:本文转自Linux 安全网,在此基础上加上自己的体会! crontab 命令 如果发现您的系统里没有这个命令,在ubuntu server 中用的是 sudo apt-get install c ...

  4. Android-Junit-Report测试报告生成——Android自动化测试学习历程

    视频地址: http://www.chuanke.com/v1983382-135467-384869.html 这个内容其实已经在用了,我在上一篇文章robotium—只有apk文件的测试中已经讲过 ...

  5. python第十三天

    这几天在欺负docker兽,很是开心,但是没想到领导突然让我去殴打openstack兽,完全没有兴趣嘛,毕竟前一阵一直在吊打它,当然啦,对于愚蠢的人类而言openstack兽是十分强大的,不过对于北方 ...

  6. 最长子串 FZU2118

    http://acm.fzu.edu.cn/problem.php?pid=2128 分析:利用strstr()函数将每个字串在原串中的首尾位置存储一下,再将首尾从小到大排一下序.(写着写着就感觉和看 ...

  7. php包含(include/require)文件时的作用域

    当一个php脚本被require/include时,他的变量作用域根据其上下文环境决定. 1.如果是在一个函数中require/include一个文件,则此文件中的变量作用域是这个函数的范围.也就是说 ...

  8. [MyBean-插件]MyBean通用报表免费无限制版本发布

      [优点]    1.开发时无需安装报表组件(可以直接用编译好的文件,注意版权说明,请自行编译一次相应的报表插件文件).    2.无带包烦恼所有版本Delphi都可以使用,不拖累Delphi版本的 ...

  9. python学习之路-day7

    本节内容: 面向对象高级语法部分 静态方法.类方法.属性方法 类的特殊方法 反射 异常处理 Socket开发基础 面向对象高级语法部分 静态方法                             ...

  10. 如何断开所有SQL Server所有的连接

    方法1: 执行以下脚本 01.declare   @sql   varchar(100) 02.  03.while   1=1 04.begin 05.  06.select   top   1   ...