简体   繁体   中英

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". 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. 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.

However you can implement HttpSessionListener and store/restore your attributes when session is created and destroyed.

What exactly do you mean by suspended ? Do you mean serialized ? In that case take a look at the transient keyword.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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