首页 > 其他 > 详细

初识session

时间:2018-06-26 15:33:19      阅读:231      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!