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 会帮你在网站上所打的文字或是一些选择, 都纪 ...
随机推荐
- iOS崩溃日志记录工具--CrashlyTics
http://try.crashlytics.com Crashlytics优势: 1.Crashlytics基本不会漏掉任何应用崩溃的信息 2.Crashlytics对崩溃日志管理很人性化,会根据崩 ...
- asp.net GDI+绘制多个矩形
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- okhttp-utils的封装之okhttp的使用
HTTP是现代应用的网络.这就是我们如何交换数据和媒体.让你的东西做HTTP有效负载的速度和节省带宽. okhttp是HTTP客户端的有效默认: HTTP 2支持允许所有请求相同的主机共享一个插座. ...
- C_C++圣战(摘录)
我的回忆和有趣的故事 --- C/C++圣战篇 李维 (声明以下的这篇文章内容是我个人的回忆以及看法,没有任何特别的偏见,许多的事情是根据我的记忆以及从许多人的诉说中得知的,也许内容不是百分之百的正确 ...
- PTA List Components
For a given undirected graph with N vertices and E edges, please list all the connected components b ...
- System.IO.Directory类
1.参考的博客:System.IO.Directory类和System.DirectoryInfo类(http://blog.sina.com.cn/s/blog_614f473101017du4.h ...
- Dynamic CRM2016在一台本地服务器安装部署
在本地单独一台服务器上安装部署CRM2016时需要提前安装好CRM软件需要的必备软件,具体需要安装的组件如下截图:其中required为必须具备的安装组件.license可以采用微软官网的90天测试版 ...
- Android自动化预备(下)
上次说道:要具备的一些知识,还有多ADB得理解 本次继续ADB理解: AndroidDebugBridge debugBridge =AndroidDebugBridge.createBridge(& ...
- Android Log介绍
android.util.Log常用的方法有以下5个:Log.v() ,Log.d() ,Log.i() ,Log.w() ,Log.e() .按照日志级别从高到低为ERROR, WARN, INFO ...
- 問題排查:建立選單時的錯誤 errcode:65318,errmsg:must use utf-8 charset hint: [Vwda70520vr18]
目前已知:程式存檔時,將檔案編碼格式設定成 UTF-8 即可. 筆者使用的文字編輯器為 Editplus 3.51,檔案編碼格式很多帶 UTF8.Unicode 字眼的選項,選 UTF-8 即可.