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 会帮你在网站上所打的文字或是一些选择, 都纪 ...
随机推荐
- docker创建镜像的几个命令
docker create -it --name mongodb mongo/myubuntu1. docker start mongodbdocker exec -it mongodb bash i ...
- java的四种取整方法
java 中取整操作提供了四种方法:分别是: public static double ceil(double a)//向上取整 public static double floor(double ...
- 开发板通过UART向主机发送数据
/********************************* 代码功能:开发板通过UART向主机发送数据 使用函数: Serial.begin(数据传输的波特率); Serial.printl ...
- java利用jxl操作Excel
/** * 把从数据库查询到的数据,写入电子表格 * * @throws Exception */ public void createXls() throws Exception { Dao dao ...
- static关键字用法
java中static关键字可用于修饰: 1.属性:表示该属性变量在类被加载时即被创建并初始化,类加载过程只进行一次,因此静态变量也只被创建一次 2.方法:静态方法为类的公有方法,可直接用‘类名.方法 ...
- 新手入门Java需要注意的问题
学习编程,虽然有老师教,但是更重要的事自学.这是很重要的. 现在互联网上面资源太多了,这也就有一个问题:怎么才能在一定时间内学习该知识,掌握该技能呢? 理论联系实践! 学以致用!! 网上的资源太多了, ...
- JS 菜单栏一直悬浮在顶部代码
只需要把下面代码放到js中: $(function(){ //获取要定位元素距离浏览器顶部的距离 var navH = $(".menu&quo ...
- eclipse插件egit安装使用
转载http://blog.csdn.net/zhangdaiscott/article/details/16939165 安装问题解决: 1 Cannot complete the install ...
- Browser设置搜索引擎
Browser设置搜索引擎,在com.android.browser.preferences.GeneralPreferencesFragment中加载R.xml.general_preference ...
- 【Java学习笔记】泛型
泛型: jdk1.5出现的安全机制 好处: 1.将运行时期的问题ClassCastException转到了编译时期. 2.避免了强制转换的麻烦. <>: 什么时候用? 当操作的引用数据类型 ...