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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:55:29+00:00 2026-05-15T08:55:29+00:00

I need to invoke a Servlet on application startup since it contains some application

  • 0

I need to invoke a Servlet on application startup since it contains some application initialization logic.

I know I can set load-on-startup configuration, but this will only invoke Servlet’s init method. I need to invoke a doGet method and pass some Url parameters to it.
Servlet doGet method expects ServletRequest and ServletResponse objects.

Also, since this is clustered application, I need to know exactly what node I am accessing (since one option is just to open a socket and invoke a Servlet).

What is the best option to perform this?

EDIT: As a clarification, Servlet already exist and can not be modified. Until now, someone would manually invoke the Servlet from the browser. I need to automatize 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-15T08:55:30+00:00Added an answer on May 15, 2026 at 8:55 am

    The best option is to refactor whatever logic you have in the doGet method into a separate method that can be invoked both from init and doGet.

    If you really can’t refactor the logic (which really is the only good option), you can use some mock library. Google says Spring’s mock objects are popular.

    Having a usable implementation of HttpServletRequest and HttpServletResponse, make a servlet loaded with load-on-startup, and from its init method, locate the relevant servlet from the current ServletContext, and invoke doGet with the appropriate request and response objects. (Yes, it’s a pretty bad kludge, but you’ll have to do something like this.)

    Edit: If you don’t want to hack the WAR file, maybe you should check if your servlet container has the possibility to run some kind of hooks after you re/deploy a web app.

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

Sidebar

Related Questions

My Java web application contains a startup servlet. Its init() method is invoked, when
i have a need to invoke some methods asynchrounously. On startup, the app does
I need to invoke a call from code how can i do it ?
I need to invoke a mapreduce job from java application. I use ToolRunner.run(new Validation(),
I need to invoke a bash script by itself with a different set of
In our Spring App, under some test scenarios we need to invoke a particular
I need to invoke a method on a class using reflection. The class contains
I have servlet in my web.xml but i don't want my application to load
I am making an application where I need to invoke requests in multiple view
I'm developing an application where I the need to invoke a method of a

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.