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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:11:44+00:00 2026-05-16T16:11:44+00:00

Is there a way to attach to events like asp.net’s Application_Start and Begin_Request in

  • 0

Is there a way to attach to events like asp.net’s “Application_Start” and “Begin_Request” in Java/Tomcat/JSP web projects? I would really rather not use JSF or an extra framework(Spring, Struts). I do not want to do it on a per-page basis with anything like ‘jspInit’, a global event handler is the goal.

In the event that I am stuck in the .net way of doing things, the point is to have a central place to initialize IoC containers (Application_Start), and implement a ‘One database transaction per request’ workflow (Begin_Request).

Thanks.

  • 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-16T16:11:45+00:00Added an answer on May 16, 2026 at 4:11 pm

    In the Java EE (Servlets+JSPs) world, the equivalent functionality can be obtained by implementing the relevant interfaces standardized by the Java EE specification.

    The equivalent of the Application concept is the Web Context or the Servlet context. Sessions and Requests are the same concept in Java EE as .Net. There are relevant listener classes that need to be implemented in order to hook onto the relevant events in

    • the lifecyle of an application (ServletContextListener and ServletContextAttributeListener),
    • requests served by the application (ServletRequestListener and ServletRequestAttributeListener) or
    • sessions established by the same (HttpSessionListener and HttpSessionActivationListener).

    More information on this can be found in the Java EE 5 tutorial on the Servlet lifecycle. The interfaces continue to hold good for Java EE 6 as well.

    Filters vs ServletRequestListener

    If you’ve read the comments, you would have noticed that it is possible to do preprocessing and postprocessing of requests by implementing a ServletRequestListener or a Filter.

    I would suggest that you utilize Filters (as did BalusC). This is because the Filter will be invoked everytime a request is sent to a particular URL, and is often the most effective way of ensuring that all requests to a URL receive the same ‘treatment’.

    The reasons for this are found in the Java EE API documentation on the ServletRequestListener:

    Interface for receiving notification
    events about requests coming into and
    going out of scope of a web
    application.

    A ServletRequest is defined as coming
    into scope of a web application when
    it is about to enter the first servlet
    or filter of the web application, and
    as going out of scope as it exits the
    last servlet or the first filter in
    the chain.

    When you use a ServletRequestListener, you must note that the requestInitialized and requestDestroyed events are fired only once per request (unlike the Filter where the doFilter method is invoked everytime the Filter is invoked in a processing pipeline). Since Filters are the usual way of performing actions before and after requests (I haven’t seen a lot of people use ServletRequestListeners), I would suggest that you utlize filters in such a context.

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

Sidebar

Related Questions

Is there a way to attach an event to a foreign / separate window
Is there any way to automatically launch an application on USB attach or CD
Is there way in next piece of code to only get the first record?
is there way thats i can preselect an item when the page loads or
Is there a way to enforce constraint checking in MSSQL only when inserting new
Is there any way to check whether a file is locked without using a
Is there a way to find the name of the program that is running
Is there a way to hide radio buttons inside a RadioButtonList control programmatically?
Is there a way to find the number of files of a specific type
Is there a way to take over the Entity Framework class builder? 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.