如何检测网页在Web应用程序中使用的jsp

时间:2022-06-01 16:41:01

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.

我想检测何时在Web应用程序中发生jsp中的包含,特别是包含哪个页面。我想在请求菜单页面时执行此操作。一种选择是覆盖PageContext但事实证明你不能在任何地方访问它来包装它。据我所知,PageContext是唯一提供包含回调的类。我可能会使用响应过滤器来检测包含何时发生,但看起来不可能。

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.

我想要实现的是,当请求jsp时,我想在请求的jsp的末尾附加所有包含作为注释。

1 个解决方案

#1


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.

一些(大多数?)app-servers将重用请求对象用于动态包含 - 我知道Tomcat和Weblogic。因此,您可以创建一个过滤器,在第一次调用时将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).

但我不得不问:这样做的真正原因是什么?我无法想象在生产代码中这样做,所以我猜你正在寻找构建某种依赖图。如果是这种情况,我建议创建静态分析工具而不是动态。如果您的应用程序足够复杂以至于需要这样的映射,那么它将具有条件包含的可能性很好,除非您可以执行所有可能的路径(并且不太可能),否则动态工具将无法检测到它。

#1


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.

一些(大多数?)app-servers将重用请求对象用于动态包含 - 我知道Tomcat和Weblogic。因此,您可以创建一个过滤器,在第一次调用时将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).

但我不得不问:这样做的真正原因是什么?我无法想象在生产代码中这样做,所以我猜你正在寻找构建某种依赖图。如果是这种情况,我建议创建静态分析工具而不是动态。如果您的应用程序足够复杂以至于需要这样的映射,那么它将具有条件包含的可能性很好,除非您可以执行所有可能的路径(并且不太可能),否则动态工具将无法检测到它。