Java Servlet Session 里面应该包含什么以及重定向
我想知道哪些数据应该进入会话。假设我有一个用户对象,其中包含表示图像链接的对象列表。我应该在会话中保存用户对象的用户名并使用它来查询数据库中的用户对象以及图像的链接,还是应该保存整个对象、会话中包含的列表并在没有更新的情况下使用它需要吗?这是一个糟糕的策略吗?
我对此很陌生,所以如果这没有任何意义,我很抱歉。如果 requestdispatcher 代替了 sendredirect,是否可以执行encodeurl?看起来如果我使用请求调度程序,我必须在 cookie 中发送 jessesion id。
I was wondering what data should go into a session. Say I had a user object that had a list of objects that represent links to images. Should I save the username of the user object in the session and use that to query the db for the user object with the links to the images, or should I save the entire object, list included in the session and use that if no updates are needed? Is this a bad strategy?
I am new at this so I am sorry if this does not make any sense. Also is it possible to do encodeurl if the requestdispatcher is being insteand of sendredirect? It seems like if I use the request dispatcher I have to send the jessesion id in the cookie.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

在会话中存储完整的对象图:
优点:
缺点:
话虽如此,您应该保持 HTTP 会话尽可能小,并且当性能成为问题(频繁的数据库查询)时考虑缓存。
Storing the full object graph in session:
Pros:
Cons:
That being said you should keep the HTTP session as small as possible and when performance becomes a problem (frequent database queries) think about caching.