aspose file tools*
The moose likes Servlets and the fly likes ServletContextListener Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContextListener Question" Watch "ServletContextListener Question" New topic
Author

ServletContextListener Question

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
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
SCJP
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
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

Joined: Jan 10, 2002
Posts: 61201
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
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

Joined: Sep 30, 2004
Posts: 239
Researching filters now. This may be what I am afer.
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContextListener Question