RequestContextHolder.currentRequestAttributes() and accessing HTTP Session

Posted by Umesh Awasthi on Programmers See other posts from Programmers or by Umesh Awasthi
Published on 2013-10-27T16:21:52Z Indexed on 2013/10/27 22:00 UTC
Read the original article Hit count: 299

Filed under:
|
|

Need to access HTTP session for fetching as well storing some information.I am using Spring-MVC for my application and i have 2 options here.

  1. User Request/ Session in my Controller method and do my work
  2. Use RequestContextHolde to access Session information.

I am separating some calculation logic from Controller and want to access Session information in this new layer and for that i have 2 options

  1. Pass session or Request object to other method in other layer and perform my work.
  2. use RequestContextHolder.currentRequestAttributes() to access request/ session and perform my work.

I am not sure which is right way to go? with second approach, i can see that method calling will be more clean and i need not to pass request/ session each time.

© Programmers or respective owner

Related posts about java

Related posts about session