cookie and session

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的更多相关文章
- Cookie和Session的总结
1.开篇 在之前学习这一段的时候我一直有点没弄清楚,其实对Session这块的理解还可以,但是Cookie感觉始终还是欠缺点火候.之后的很长一段时间都基本上很少用Cookie了,渐渐的也淡忘了这一块的 ...
- java的会话管理:Cookie和Session
java的会话管理:Cookie和Session 1.什么是会话 此处的是指客户端(浏览器)和服务端之间的数据传输.例如用户登录,购物车等 会话管理就是管理浏览器客户端和服务端之间会话过程产生的会话数 ...
- Cookie和Session的那些事儿
Cookie和Session都是为了保持用户的访问状态,一方面为了方便业务实现,另一方面为了简化服务端的程序设计,提高访问性能.Cookie是客户端(也就是浏览器端)的技术,设置了Cookie之后,每 ...
- django的cookie和session以及内置信号、缓存
cookie和session cookie和session的作用: cookie和session都记录了客户端的某种状态,用来跟踪用户访问网站的整个回话.两者最大的区别是cookie的信息是存放在浏览 ...
- Cookie和Session的区别
前言 HTTP是一种无状态的协议,为了分辨链接是谁发起的,就需要我们自己去解决这个问题.不然有些情况下即使是同一个网站我们每打开一个页面也都要登录一下.而Session和Cookie就是为解决这个问题 ...
- 本地数据Store。Cookie,Session,Cache的理解。Timer类主要用于定时性、周期性任务 的触发。刷新Store,Panel
本地数据Store var monthStore = Ext.create('Ext.data.Store', { storeId : 'monthStore', autoLoad : false, ...
- Cookie与Session
再说Cookie与Session之前,先要了解一下http协议. 何为http协议: http协议即超文本传输协议,一种基于浏览器请求与服务器响应的协议,该协议主要的特点就是它是一种无状态的协议(只针 ...
- 【转】Cookie和Session区别和联系详解
会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...
- 理解Cookie和Session机制(转)
目录[-] Cookie机制 什么是Cookie 记录用户访问次数 Cookie的不可跨域名性 Unicode编码:保存中文 BASE64编码:保存二进制图片 设置Cookie的所有属性 Cookie ...
- cookie 和session 的区别详解
这些都是基础知识,不过有必要做深入了解.先简单介绍一下. 二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cookie 会帮你在网站上所打的文字或是一些选择, 都纪 ...
随机推荐
- poj 2337 有向图输出欧拉路径
Catenyms Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10186 Accepted: 2650 Descrip ...
- C# 关于时间
1.2016/7/8 00:10:10 转换成 2016-07-08T 00:10:10 在用VB动态调用WevService的时候,传入的时间格式为2016/7/8 00:10:10,导致调用出错, ...
- 使用Debussy+ModelSim快速查看前仿真波形
sim.do文件 quit -sim set PATH1 D:/Program/modelsim/vivado_lib set PATH2 D:/Program/Vivado/Vivado/2014. ...
- JS打印页面
打印 整个html页面(PS:样式要写在页面里面才能打印(就是用内部样式)) <a id="dayi" runat="server ...
- 什么是侧翼区(flanking region)和侧翼区单核苷酸多态性(Flanking SNPs)
侧翼区(flanking region) 根据维基定义:The 5' flanking region is a region of DNA that is adjacent to the 5' end ...
- Tornado sqlalchemy
上篇文章提到了,最近在用 Python 做一个网站.除了 Tornado ,主要还用到了 SQLAlchemy.这篇就是介绍我在使用 SQLAlchemy 的过程中,学到的一些知识. 首先说下,由于最 ...
- 修改myeclipse的servlet模板
今天修改myeclipse的servlet模板时,发生 Could not create the view: An unexpected exception was thrown.错误. 解决方案:1 ...
- javascript 的 clientX用法
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- ArcGIS删除部分数据后全图范围不正确
我有一个全国地图的图层,现在删除图层中其他省份,只保留山东省的图形,但是点击全图后,全图范围仍然是全国地图时候的全图范围,使用的版本是ArcGIS9.3,数据存放在9.3的个人数据库中(Perso ...
- 磁盘配额quota应用
1.文件系统支持 quota是针对整个文件系统来进行规划,所以我们得先查一下/home是否是个独立的文件系统. [root@Monitor home]# df -h /home Filesystem ...