The moose likes Struts and the fly likes JSP Filter with Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JSP Filter with Struts" Watch "JSP Filter with Struts" New topic

JSP Filter with Struts

Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
I am attempting to create a simple JSP Filter for my Struts-based application. The filter is supposed to print a line to stdout any time a JSP is accessed.

The problem I am having is that when I access my JSPs with the following filter mapping, I am not able to see the output in stdout. It's almost like the jsp is not found with the below <url-pattern>:

However, if I use a mapping like the one below, then I am able to see the output in stdout for every JSP and every other resource accessed:

My goal is find a way to only see the ouptut in stdout for JSPs and not everything else. Please advise!

My code:

Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
I figured out the answer to my own question. In Tomcat 4.1.31 (servlet spec 2.3), the <filter-mapping> only applies to requests (for example, from a browser). So the filters are not applied to the Struts FORWARDS.

However in Tomcat 5 (servlet spec 2.4), there is NEW support for a <dispatcher> element with FORWARD.

I am surprised that I was not able to find this answer on a search engine since it would appear to be fairly common. Anyway, for anyone interested, check out the 2.4 servlet spec on page 55 for details.
I agree. Here's the link:
subject: JSP Filter with Struts
It's not a secret anymore!