码迷,mamicode.com
首页 > 其他好文 > 详细

初识session

时间:2018-06-26 16:04:20      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:sessionid   returns   对象   随机   初识   return   http   sso   通过   

session是服务端产生,保存在服务端的。

session的获取是通过httpservletrequest的getSession(boolean create)  Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.或者getSession()  Returns the current session associated with this request, or if the request does not have a session, creates one.

session的失效通过httpsession的invalidate()    Invalidates this session then unbinds any objects bound to it.。

session的工作原理。

服务器会为每个回话创建一个session与之绑定使用。服务器会为应用创建一个session列表,这是个map集合。map是用一个随机串作为key,而value是session对象的引用。

当用户进行一次请求时,通过request.getSession()之后,会在map中添加一个key和与之对应的session对象作为value。将session放入map之后。还会将key作为value与jsessionid绑定,放入cookie传到前台,前台将这个cookie放入浏览器缓存中,当再次请求时会将这个cookie传回后台,后台根据jsessionid的value去map中读取对应的session对象。进行一系列的操作。

 所谓的会话结束,并不是单单的关闭浏览器,而是指session失效。

初识session

标签:sessionid   returns   对象   随机   初识   return   http   sso   通过   

原文地址:https://www.cnblogs.com/wangyanei2017/p/9229123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!