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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:09:28+00:00 2026-06-16T09:09:28+00:00

I want to create a base controller class that my other controllers will inherit

  • 0

I want to create a base controller class that my other controllers will inherit from. I have a simple public api that takes the authentication token via the query string, so I want to do this:

public class MyBaseController {
   private String token = "";
   public MyBaseController() {
   }
}

And then my real controller would be like:

@Controller
@RequestMapping("/api/users")
public class UserController extends MyBaseControler {

  // controller methods here
}

My question is, how can i get access to the HttpServletRequest in my base controller, and get the querystring parameter “?token=abc123” value and set the token var with the value.

Is this thread safe? It is my understanding that there will be a new controller instance per request correct?

  • 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-16T09:09:29+00:00Added an answer on June 16, 2026 at 9:09 am

    Your controllers are better off if they’re stateless.

    You can inject them with Spring services as needed, but I don’t see any reason why they have to hang onto the value of the token as a member variable.

    It’s far more likely that you’ll want to store the token in session scope. I think your idea is wrong-headed.

    I’ll point out that Spring itself has moved away from inheritance for controllers. They’re all annotation-based now, with no common base class or interface. Why do you think devolving back to the design they abandoned is a good thing?

    You don’t need a base controller, either.

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

Sidebar

Related Questions

I have controller with action new , and I want it to create ActiveRecord::Base
I want to create a PDO class for handling data base connections. Here is
I've created a base class, and 2 inherited classes. I want to create a
i want create a custom json data from the mssql 2008 results so that
I have three models that I want to interact with each other. Kase, Person
I have a standard model set. I have a base context class that inherits
In visual studio 2005: I want to create a dll base on another dll.
I want to create a tab bar like portion on the base of the
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means

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.