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 会帮你在网站上所打的文字或是一些选择, 都纪 ...
随机推荐
- Linux shell之sed
sed编辑器逐行处理输入,然后把结果发送到屏幕. -i选项:直接作用源文件,源文件将被修改. sed命令和选项: a\ 在当前行后添加一行或多行 c\ 用新文本替换当前行中的文本 d 删除行 i\ 在 ...
- JQuery Mobile 页面参数传递(转)
在单页模版中使用基于HTTP的方式通过POST和GET请求传递参数,而在多页模版中不需要与服务器进行通信,通常在多页模版中有以下三种方法来实现页面间的参数传递. 1.GET方式:在前一个页面生成参数并 ...
- HDOJ 1512 几乎模板的左偏树
题目大意:有n个猴子.每个猴子有一个力量值,力量值越大表示这个猴子打架越厉害.如果2个猴子不认识,他们就会找他们认识的猴子中力量最大的出来单挑,单挑不论输赢,单挑的2个猴子力量值减半,这2拨猴子就都认 ...
- HttpModule的一些初步认识
新建一个类 ValidaterHttpModuleEvents继承管道接口 IHttpModule,代码如下 public class ValidaterHttpModuleEvents:IHttpM ...
- ZT 趋势移动安全apk
趋势移动安全 应用截图 应用简介 趋势移动安全( Mobile Security) 是一款专业的Android移动安全软件.利用趋势科技世界领先的云安全技术,保护用户避免被移动恶意程序骚扰,避免个 ...
- java 抽象类与接口的区别
在Java 语言中, abstract class 和interface 是支持抽象类 定义的两种机制.正是由于这两种机制的存在,才赋予 了Java强大的 面向对象能力.abstract class和 ...
- 在spark中操作mysql数据 ---- spark学习之七
使用spark的 DataFrame 来操作mysql数据. DataFrame是比RDD更高一个级别的抽象,可以应用SQL语句进行操作,详细参考: https://spark.apache.org/ ...
- 洛谷P2014 选课 (树形dp)
10月1日更新.题目:在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程来学习,在课程里有些课程必须在某些课程之前学习,如高等数学总是在其它课程之前学习.现在有N门功课,每门课有个学分 ...
- php protected封装
<?//父类class father{ public function a(){ echo 'father->a()'.'<br>'; echo "func ...
- FreeBSD_11-系统管理——{Part_2-核心}
一.Managing Services in FreeBSD Service restart will only work if it is set to YES in /etc/rc.conf. T ...