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

  • Home
  • SEARCH
  • 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 8847653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:14:30+00:00 2026-06-14T12:14:30+00:00

In my web application i want to have certain necessary things in all of

  • 0

In my web application i want to have certain necessary things in all of the “pages” of it, such as connection to the database, user information, template processing, etc. Until recently i would have an abstract servlet that would init all of the above in its doGet or doPost method, define the abstract method doLocalLogic(HttpServletRequest req, HttpServletResponse res) and would call it from the doGet/doPost method. All the extending classes would enjoy the database connection, user info, etc. Unfortunately, it turned out to be bad practice.

What I am thinking now is to create an abstract class that does all that, all the logic from my servlets would be moved to the children of this class, and the servlets would just create instances of those children.

However, that leads to creating one more class per every page in my app. Moreover, when you create a new servlet, you don’t have any clues in the form of abstract methods you need to override, as you would having an abstract servlet.

Is there a better way of doing it?

  • 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-14T12:14:31+00:00Added an answer on June 14, 2026 at 12:14 pm

    First of all I would argue that your approach with doLocalLogic() is not bad as long as you are passing this local logic through parameters, not through fields (threads are shared between requests/threads):

    public void doLocalLogic(
      Connection connection,
      UserInformation user,
      //...
      HttpServletRequest req,
      HttpServletResponse res
    )
    

    The only problem is that you do prepare a lot of data even if you don’t need them in the servlet. And it’s not scalable.

    What you really need is a more robust… framework. First you probably need a web framework to avoid coding to servlet API directly. Secondly you need IoC like Spring to manage your dependencies. Instead of eagerly creating them and passing over, each service just asks for required dependencies.

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

Sidebar

Related Questions

I have developed a web application driven by a mysql database that stores information
I want to write a web application and want to use Ruby. I have
I have created blank Asp.Net-MVC 3 web application and want to write my own
I have a .Net web application that I want to take a copy of
I have a web application that I want to run some system tests on,
I have a web application that I want to sync with Flickr. I don't
I have an ASP.NET web application and I want to be able to take
I have a google web application project that I want to host on github.
In my web application we have many users.I want to set permission for each
In my web application I have taken a ajax calendar in that i want

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.