request.getSession()。getId()和request.getSession(false)之间的区别? [英] Difference between request.getSession().getId() and request.getSession(false)?

查看:806
本文介绍了request.getSession()。getId()和request.getSession(false)之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些电话在会话方面实际上意味着什么?

What do these calls actually mean in terms of session?

System.out.println("print1: "+request.getSession().getId());
System.out.println("print2: "+request.getSession(false));

输出

print1: D94146A347D95563186EB7525726336B
print2: org.apache.catalina.session.StandardSessionFacade@d52411


推荐答案

HttpSession session = request.getSession(); 在我们要求的服务方法中会话和所有事情都会自动生成,就像创建HttpSession对象一样。无需生成唯一会话ID。无需创建新的Cookie对象。一切都在幕后自动发生。

HttpSession session = request.getSession(); Inside the service method we ask for the session and every thing gets automatically, like the creation of the HttpSession object. There is no need to generate the unique session id. There is no need to make a new Cookie object. Everything happens automatically behind the scenes.

一旦调用请求对象的方法 getSession(),会话的新对象就会被创建容器和生成的唯一会话ID以维护会话。此会话ID将传回给响应对象,以便每当客户端发出任何请求时,它还应将会话ID与requsest对象相关联,以便容器可以识别会话。

As soon as call the method getSession() of the request object a new object of the session gets created by the container and a unique session id generated to maintain the session. This session id is transmitted back to the response object so that whenever the client makes any request then it should also attach the session id with the requsest object so that the container can identify the session.

request.getSession(false):此方法将检查Session是否已存在。如果它存在则会返回已存在的Session。如果此请求尚未存在Session,则此方法将返回NULL,这意味着此方法表示请求之前没有会话。

request.getSession(false) : This method will check whether Session already existed for the request or not. If it existed then it will return the already existed Session. If Session is not already existed for this request then this method will return NULL, that means this method says that the request does not have a Session previously.

这篇关于request.getSession()。getId()和request.getSession(false)之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆