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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:02:18+00:00 2026-06-07T23:02:18+00:00

I am involved in a jsp/servlet application. The application stores objects needed in session

  • 0

I am involved in a jsp/servlet application. The application stores objects needed in session or request. However the same object can be injected into session or request in multiple locations. In other words, instead of writing

HomeBean homeBean = (HomeBean) request.getSession(false).getAttribute("homeBean");

I will write

HomeBean homeBean = BeanStore.getHomeBean();

Am I overthinking or overdesigning ?

  • 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-07T23:02:20+00:00Added an answer on June 7, 2026 at 11:02 pm

    In some frameworks like spring or cdi you can inject session or even some session attribute directly to your business component, something like:

    @Inject
    private HomeBean homeBean;
    

    Also instead of polluting your code with HTTP session access code just fetch the object once and pass it where needed. It will make reading and testing easier.

    Note that your BeanStore.getHomeBean() is really hard to write correctly if you really don’t want to pass HttpSession directly. Servlet filters and ThreadLocal, here I come! Not to mention I find such static “factory” quite ugly.


    Side note, in:

    request.getSession(false).getAttribute("homeBean")
    

    request.getSession(false) will often return null, leaving you with nasty NullPointerException. Prefer true or no parameters at all in this case.

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

Sidebar

Related Questions

I can't get my controller involved when the request is fired. I see the
I am involved in the development of a WPF Prism application which uses the
I have a fairly involved managed data model which has a central object with
I have been involved in building a custum QGIS application in which live data
I am currently involved with an Application where I need to design the UI
I'm not very experienced in JSP. I have an application, which uses the Spring
So I have an object and I want to add a bunch of sub-objects
In my application, I have both html and JSP files. I need them both
I'm currently involved in a heavily localised WPF application and we've had a bug
I'm involved in an application migration project. This application is supposed to execute some

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.