0

I have a (browser based) web application. On each page, I want to have a little label and link in a corner that displays the user's username and other account information along with a logout button. The information that will be displayed is immutable.

Should I store that account information in session attributes when a user logs in and forget about it or should I use a filter/interceptor and load it on each request in the request attributes?

2
  • What would the effect of logging out be, if the information is only stored in the request?
    – user40980
    Commented Jul 10, 2013 at 15:43
  • @MichaelT I wasn't clear about that. For authentication, I only store the account id in the session. Then on each request that needs your account details, I retrieve all of them (account entity). The label only needs some of that info. Commented Jul 10, 2013 at 15:44

2 Answers 2

1

I would use a Session, as the information is sensitive. So the information displayed in your case would be (Account Information and UserName.) If it was only the UserName I would have thought of Request Scope, but since it is Account Information (Assuming Account numbers, etc) I would go for a session. Once the session is out, the user needs to log in again.

Or I would not display anything but the userName and the logout button.

3
  • Both request and session scope are only relevant on the server, why do you think it is safer in the session? Commented Jul 15, 2013 at 17:54
  • Read this. You will understand it better; stackoverflow.com/questions/7031885/…
    – JNL
    Commented Jul 15, 2013 at 17:57
  • This should also be helpful. balusc.blogspot.com/2011/09/… If you found the answer useful, you can please upvote it or mark it as a correct answer. Would appreciate it. Thanks
    – JNL
    Commented Jul 15, 2013 at 17:58
1

You could do both,

If your application is big, and you choose to load the user's account info and display it on the page, it will cost you an sql query per page, which is an overhead.

To escape the overhead of making same sql query per page, use sessions!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.