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 7890701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:25:27+00:00 2026-06-03T06:25:27+00:00

I have numerous controllers in my application that extend a central controller class. Currently,

  • 0

I have numerous controllers in my application that extend a central controller class. Currently, in every controller function, I have to pass the request into this function in order for my function to grab the current username. Is it possible for this controller class to get the request on it’s own without requiring it as an extra parameter?

public class Controller {
    protected String environment;

    public Controller () {

    }

    public ModelAndView prepareModel (HttpServletRequest request, ModelAndView model) {
        contentDao.clearExpiredLocks();

        model.addObject("currentUser", contentDao.findUser(request.getRemoteUser()));

        //define current environment
        this.environment = (request.getRequestURL().indexOf("localhost") > 0) ? "dev" : "uat";
        model.addObject("environment", this.environment);
  • 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-06-03T06:25:28+00:00Added an answer on June 3, 2026 at 6:25 am

    You can get the current HttpServletRequest as follows:

    HttpServletRequest request = (HttpServletRequest) RequestContextHolder
        .currentRequestAttributes()
        .resolveReference(RequestAttributes.REFERENCE_REQUEST); 
    

    You can use this code in a method of your controller, or use it to expose request as a request-scoped bean and inject the corresponding scoped proxy as a field of your controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application developed with Spring 2.5. The application has numerous controllers,
In my Rails 3 application I have numerous models that have columns that have
I have numerous functions (unknown at design time) that each take a specific number
In my program I have numerous Entity classes with a Texture2D attribute that are
We have numerous python classes that do not seem to need __init__ , initialising
I'm creating a Django powered website that will have numerous applications (Blog, Shop, Portfolio,
I have a View for creating a customer that contains numerous textboxes. After the
We use Team Foundation Server and have numerous ASP.NET Web Application Projects. Each of
I have numerous buttons on my page with the same class names. However these
In my app there are numerous view controllers which have their own purposes. However,

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.