简体   繁体   中英

How set session attribute during session creation?

It is needed to create session, do some action and save result in session, before session is exposed in other code parts. There is a HttpSessionListenr but it handles session created event after session is created. It seem there are no guaranties that session accessed between listener receive event. Is it true?

How to override session creation mechanism or execute code before session is created?

I can think of two ways:

  1. Access the session using a helper method.
  2. Create a Filter to initialize the session.

Option 1 means that your code must use the helper. The helper will initialize the session, if needed.

Option 2 means that the session will be initialized for all filtered requests, even if not needed.

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