• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContextListener Question

 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • 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: 239
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 239
  • Mark post as helpful
  • send pies
  • 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: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Researching filters now. This may be what I am afer.
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic