`
geeksun
  • 浏览: 952944 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

session和cookie的区别

 
阅读更多

在web前端中经常会用到session,有时也会用到cookie,那么,session和cookie的区别是什么呢?

我的理解是,session是每个请求在服务器端保存的一段会话信息,每一个请求的session的另外的请求的session都不同,这样,session用来区别不同的请求。

session的实现机制是使用cookie或jsessionid来实现的,当cookie被禁时,就使用url重写,即jsessionid来实现。

这时可在url栏看到 url?jsession=xxxxx的字样。

cookie主要用来保存客户端的用户信息,可分成会话session和持久化session,会话session的生命周期是在浏览器进程内,当浏览器关掉时,会话session即消失,持久化session保存在客户机的硬盘上,会在一定时期内存在。

关于session的进一步解释:

If the user's browser is cookie-enabled, the session ID is stored as a cookie. As an alternative, the session ID can be conveyed to the servlet by URL rewriting, in which the session ID is appended to the URL of the servlet or JavaServer Pages (JSP) file from which the user is making requests. For requests over HTTPS or Secure Sockets Layer (SSL), Another alternative is to use SSL information to identify the session


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics