简体   繁体   English

Java EE会话:您可以将某些属性存储为非持久性吗?

[英]Java EE sessions: Can you store some attributes as non-persistent?

Would I be able to store session variables in such a way that some of them can be brought back if the session is suspended while others are not? 我是否能够以这样的方式存储会话变量:如果会话被挂起而另一些会话变量未被挂起,则其中的一些可以被带回?

Let's say I have 2 session variables named "A" and "B". 假设我有两个名为“ A”和“ B”的会话变量。 I want "A" to be persisted and brought back if the session is ever suspended but I do not want "B" to ever be saved anywhere. 如果会话被暂停,我希望保留“ A”并将其恢复,但是我不希望将“ B”保存在任何位置。 I want it to be lost, for security related reasons. 由于安全性原因,我希望它丢失。

Short answer is no. 简短的答案是没有。 Besides, session normally live relatively short time (eg like 30 minutes) and all attributes will be gone after that. 此外,会话通常会持续较短的时间(例如30分钟),之后所有属性都将消失。

However you can implement HttpSessionListener and store/restore your attributes when session is created and destroyed. 但是,可以在创建和销毁会话时实现HttpSessionListener并存储/恢复属性。

What exactly do you mean by suspended ? 停权到底是什么意思? Do you mean serialized ? 您是说序列化的吗? In that case take a look at the transient keyword. 在这种情况下,请看一下transient关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM