会话变量存储在 Java Web 应用程序中的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24978143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where session variable is stored in java web application
提问by Youssef
1- Where session variables is stored in java web application ? on the client or the server side ?
1- 会话变量存储在 java web 应用程序中的什么地方?在客户端还是服务器端?
2- If i put a lot of objects and variables through the session it will slow down client's requests ?
2- 如果我通过会话放置了很多对象和变量,它会减慢客户端的请求吗?
P.S In my case i use spring mvc
.
PS 就我而言,我使用spring mvc
.
采纳答案by Elliott Frisch
The "session" variable consists of two pieces, a very small session identifier which is stored on the clientusually named jSessionId
and stored as a cookie. But, the sessionId may also be encoded into URLs.
“会话”变量由两部分组成,一个非常小的会话标识符,它存储在客户端上,通常命名jSessionId
并存储为 cookie。但是,sessionId 也可以编码到 URL 中。
The second piece of a session is the actual data, and it is stored on the server. Possibly in a server-sidedatabase if the your server is part of a multi-server cluster. Each sessionis identified by that sessionId and the client sends it with every request. That is why it is designed to be verysmall.
会话的第二部分是实际数据,它存储在服务器上。如果您的服务器是多服务器集群的一部分,则可能在服务器端数据库中。每个会话由 sessionId 标识,客户端随每个请求发送它。这就是为什么它被设计得非常小。
回答by Doug Hou
Simple answer is : your session data are stored on the server side.
简单的答案是:您的会话数据存储在服务器端。
Web browser will get only an string id to identify it's session.
Web 浏览器将只获得一个字符串 id 来标识它的会话。
In fact, spring security takes more care of session information, because if users even don't login, session may not exist at all.
实际上,spring security 更关心会话信息,因为如果用户甚至不登录,会话可能根本不存在。
When I use spring mvc only, I don't use session to store important data, because session is stored in memory only. It is designed to save data temporarily.
当我只使用spring mvc时,我不使用session来存储重要数据,因为session只存储在内存中。它旨在临时保存数据。
When I use spring security, I have to save many important things in memory, such as account data which could not be transmitted on internet, and I won't load them from database every time. So I have to choose session.
我在使用spring security的时候,很多重要的东西都要保存在内存中,比如无法在网上传输的账户数据,我不会每次都从数据库中加载它们。所以我必须选择会话。
So when the server which stored login session is down, all users have logged in on this server would have to relogin to retrieve another session id.
因此,当存储登录会话的服务器关闭时,所有登录该服务器的用户都必须重新登录以检索另一个会话 ID。
Session is not always the best choice, because when we have many servers that use session data, I have to share the data among all servers, anyway, net IO is expensive for servers.
Session 并不总是最好的选择,因为当我们有很多使用 session 数据的服务器时,我必须在所有服务器之间共享数据,反正服务器的 net IO 是昂贵的。
回答by Mr_xiaoM
1.it stored on server
2.Session stored on server ,so the Object you set in it may also stored on server.Request only send a SessionId to server to indentify this users Session to other users
Session.
1.它存储在服务器上 2.Session存储在服务器上,因此您在其中设置的Object也可能存储在服务器上。Request只向服务器发送一个SessionId来识别这个用户s Session to other users
Session。