• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ServletContextListener Question

 
Ranch Hand
Posts: 240
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to have my ServletContextListener run every time a servlet is created to handle a http post request from an HTML form.

Right now it seems it only runs when I restart start TomCat.

I am mistaken on this? Does the above make sense?

Thanks,

Luke
 
Luke Shannon
Ranch Hand
Posts: 240
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am now investigating the ServletRequestListener. If I could have the code of the listener to run everytime the doPost of one of the servlets of my application executes I would be in good shape.

If anyone knows anything better please let me know.

Luke
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ServletContextListener does exactly what its name implies, it listens for changes in the ServletContext (aka application scope), not individual servlets.

What exactly are you trying to accomplish? It may be that a servlet Filter is the mechanism that you are after.
 
Luke Shannon
Ranch Hand
Posts: 240
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a servlet that receives a HTTP request (posted from an HTML form). The doPost method executes a Lucene search of some index files and displays the results (the search parameter is received from the form).

What I am after is some component that would say (before the above happens),

"Hey, a HTTP request just came in and is being handled by a doPost method. I better refresh the index files in case the files have changed since the last time the indexes where compiled."

Than this thing, whatever it may be (listener, filter, etc), would instaniate a Lucene IndexWriter, update the Index and finally destroy itself releasing its hold on the index files.

Thats what I'm after.
[ November 03, 2004: Message edited by: Luke Shannon ]
 
Luke Shannon
Ranch Hand
Posts: 240
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Researching filters now. This may be what I am afer.
 
Luke Shannon
Ranch Hand
Posts: 240
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A filter works like a charm. However it seems the requirments have changed a little and this functionality needs to be available at any point during runtime.

So I am going to move the logic into the doGet of a servlet that can be called when required. My concern now are resources (the index files) being released in time for other components to work with them.

But the issue I originally created this thread for has been resolved.

Thanks Bear.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic