This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Intercepting requests. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Intercepting requests." Watch "Intercepting requests." New topic
Author

Intercepting requests.

mani vannan
Ranch Hand

Joined: Apr 17, 2006
Posts: 47
Hello,
I am planning to write one web analytics servlet(that will intercept each requests to the tomcat server, log the request header detail into database). I dont have a clue how to route all requests to the tomcat to my analytics servlet. Should I use any filter? or any suggestion?


Mani (SCEA 1.4)<br /><a href="http://excusemeworld.com/technical/is-scjp-useful-worth-helps-job/" target="_blank" rel="nofollow"> Is SCJP Useful? Worth? Helps job?</a>
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you only need it to intercept requests for one application, then a filter will work nicely. If you need to intercept requests for all applications running under an instance of Tomcat, a Valve might be easier.

Tomcat ships with a valve that does something similar to what you're doing.
Instead of writing to a database, however, it writes to a log file.
Look in tomcat/conf/server.xml for the RequestDumperValve entry.
It's commented out by default.

Since Tomcat is open source, you can download the code to the valve to see how they're intercepting requests. This might be a good way to get started.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Intercepting requests.
 
Similar Threads
Tomcat multithread servlet
Starting out on Servlets - from Head First Servlets and JSP
What happens to threads started from a Servlet when Tomcat is stopped?
Generating requests from servlets
Default Page, How?