Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7186593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:39:49+00:00 2026-05-28T18:39:49+00:00

When in a method of a controller I need to retrieve some data from

  • 0

When in a method of a controller I need to retrieve some data from the session (often an ID that I use for user permissions and per user customization of the webpage), I write methods like this:

@RequestMapping("something")
public ModelAndView doSomething(HttpSession session) throws AuthorizationException{

PerUserModelBean bean = getSessionRelatedInfo(session);

bean.checkPermissions();



...do my stuff...

}

Which is boring because I have to repeat the session parameter for each method and I have to put that code at the beginning of each method. Not only boring, if I want to change that I have to go across all methods and change it. I’d like that session info retriavial and the checkPermissions method get called automatically before my method, and then somehow have the bean variable (perhaps as a threadlocal?) automatically filled according to the session contents. Is there some way to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:39:50+00:00Added an answer on May 28, 2026 at 6:39 pm

    Place the below method to a super class which you can use as a Base for common functionality. I am sure you have one already in place so all child classes will inherit it.

    For executing it before every method execution: you may use Filters/Interceptors/AOP, someone else may be able to give you more accurate ideas about that.

    protected HttpSession getSession(){
            ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
            return attr.getRequest().getSession();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing the code for a controller method and I need to use it
I need to call a method of controller named test() from a Javascript. Script
Consider the need to return a plain-text file from a controller method back to
I have a particularly long running method that I need to execute from my
I have a Controller method that needs to accept multipart/form-data sent by the client
Why is there a need to define a new method in RESTful controller, follow
I have a controller method that returns a jSON object and in one calling
If you have a controller method like so: @expose(json) def artists(self, action=view,artist_id=None): artists=session.query(model.Artist).all() return
I've made a very simple REST controller method with Spring 3.0.0.RC1 that uses hibernate
Some of my controller actions need to respond with different ViewResults depending whether or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.