java中sesion问题

来源:百度知道 编辑:UC知道 时间:2024/09/22 04:25:37
我对session还有些疑惑,请问 HttpSession session=request.getSession(false);中HttpSession session是创建了一个session对象吗?若是为什么还要用request.getSession在获取session对象呢?
还有为什么就是当 HttpSession session=request.getSession(false);
刷新的时候会创建了一个session对象出来呢而没有刷新的时候就没有 session对象吗,
请为有谁能帮帮我吗
恩,我知道了session是个容器,那请问一下当刷新的时候为什么就会创建了一个session会话呢

Http session is an object created on the Http server, which is normally used to hold conversational state (data) of the http client(browser).

Java's HttpServletRequest has methods to create sessions on the servlet container. method HttpServletRequest.getSession() has been overloaded so that it has two similar methods.

request.getSession() would create a new session if none exists, otherwise it just return the current session.

request.getSession(false) would return null if no session existing; it won't create a new session.

request.getSession(true) is effectively same to request.getSession()

"请问一下当刷新的时候为什么就会创建了一个session会话呢?"
--it must be your misunderstanding of the code. refreshing a page won't necessarily create a session.

额. 创建的是session... 它只是个容器.

session容器是用来管理存到session里面的对象,而且也方便取出

你以前是不是学C++的?

Java里 声明一个类类型变量只是一个引用 并没有创造对象 想要对象需要获取或者new一个

request.getS