views:

79

answers:

1

Hi,

I want to detect when an include in a jsp occurs in a web application and specifically which page is being included. I want to do this when the menu page is requested. One option is to overwrite PageContext but it turns out you can't access it anywhere to wrap it. As far as I can see PageContext is the only class which provides include callbacks. I might use a response filter to detect when an include occurs but it doesn't look like that is possible either.

Any ideas ?

What I want to achieve btw is that when a jsp is requested I want to append all the includes as a comment at the end of the requested jsp.

A: 

Some (most?) app-servers will reuse the request object for dynamic includes -- I know Tomcat and Weblogic do. So you can create a filter that inserts a List as a request attribute on first call, and updates it on subsequent calls, then have your page dump the contents of this list.

But I have to ask: what's the real reason for doing this? I can't imagine doing it in production code, so I'm guessing you're looking to build some sort of a dependency graph. And if that's the case, I'd recommend creating a static analysis tool rather than dynamic. If your application is complex enough that you need such a map, then chances are good that it will have conditional includes, which won't be detected by a dynamic tool unless you can execute all possible paths (and that's unlikely).

kdgregory
Thanks that would have worked though I have decided to create a seperate program to determine the dependencies because you can't catch declaritive includes and it seems a nicer solution in the first place. I would like to add that if anyone ever tries this don't forget to add the dispatcher elements in your filter xml in web.xml like:<filter-mapping> <filter-name>DependencyFilter</filter-name> <url-pattern>*.jsp</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher> <dispatcher>FORWARD</dispatcher></filter-mapping>
Benjamin