Patcharee Thongtra wrote:
On 08/04/2014 11:26 AM, André Warnier wrote:
Patcharee Thongtra wrote:
Hi,

Is it possible to have Tomcat do some custom actions after a specific page/file is accessed/downloaded? If so, how to?
Any suggestions are appreciated.


What kind of "custom actions", for what kind of pages/files ?

What prevents you from doing such "custom actions" in your own webapp/servlet, or in a servlet filter, after you have returned the response to the client ?


Actually I set my web app as directory listing

That's not very clear.  Can you be more specific ?

 and I would like to keep
logs after users finish download files.

What kind of logs ?
If it is information that the AccessLogValve /can/ log, then the easiest way to obtain what you want may be to just process the Access logfiles, and extract what you need.

 I do not know how to do that in
my web app. Any ideas?

As mentioned earlier, a "java servlet filter" may be the way to go.
A servlet filter "wraps" your webapp, more or less like this :

   HTTP Request from client
        |
        v
   |--- servlet filter code ---
   |    |
   |    v
   |    webapp code (servlets)
   |    |
   |    v
   |--- servlet filter code ---
        |
        v
    HTTP Response to client

In other words :
- the filter sees the Request before your webapp does
- then the webapp processes the Request and produces a Response
- then the servlet filter sees the Response before it goes out
so you can do things like keeping info about the request/response, and log it somewhere if you wish.

There are some example of servlet filters shipped with Tomcat, which you could use as base for your own servlet filter code.

Note that when it is "Tomcat itself" which serves a request for a static file, this is also done by running a servlet : the "default servlet". You can also wrap that one with a filter, as illustrated above.


Then I found tomcat is aware of downloading file done (logged in access log), so I though maybe I can make Tomcat activate my servlet after the downloaded and the servlet logs the download activity.

There is no standard method for doing this in Tomcat, that you can just enable/disable by changing the configuration. But the whole of Tomcat is open-source, so you can use any part and modify it to do what you want. Maybe the AccessLogValve for example.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to