博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cookie and session
阅读量:4951 次
发布时间:2019-06-11

本文共 3032 字,大约阅读时间需要 10 分钟。

 

 

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
filters = new ArrayList
(); Filter filter = new Filter("username", Filter.Operator.eq, username); filters.add(filter); List
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.

转载于:https://www.cnblogs.com/rixiang/p/5013472.html

你可能感兴趣的文章
SQLite移植手记1
查看>>
Java AmericanFlagSort
查看>>
Mysql远程连接报错
查看>>
C# windows程序应用与JavaScript 程序交互实现例子
查看>>
sqlServer去除字段中的中文
查看>>
HashMap详解
查看>>
Adobe Scout 入门
查看>>
51nod 1247可能的路径
查看>>
js05-DOM对象二
查看>>
mariadb BINLOG_FORMAT = STATEMENT 异常
查看>>
如何监视性能和分析等待事件
查看>>
C3P0 WARN: Establishing SSL connection without server's identity verification is not recommended
查看>>
iPhone在日本最牛,在中国输得最慘
查看>>
动态方法决议 和 消息转发
查看>>
关于UI资源获取资源的好的网站
查看>>
WPF自定义搜索框代码分享
查看>>
js 基础拓展
查看>>
Windows下常用测试命令
查看>>
SpringBoot访问html访问不了的问题
查看>>
{width=200px;height=300px;overflow:hidden}
查看>>