Logging every jsp:include

java, jsp, jstl, logging

Solution

You can implement a `Filter` and configure its mapping as following:

<filter>
    <filter-name>logging</filter-name>
    <filter-class>com.example.LoggingFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>logging</filter-name>
    <url-pattern>*.jsp</url-pattern>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

This filter will intercept all `RequestDispatcher.include()` calls, including `<jsp:include>`. To get path to the included resource, use `request.getAttribute("javax.servlet.include.servlet_path")`

Problem

I want to log every `<jsp:include>` tag. Does the JavaServer Pages Standard Tag Library (JSTL) support logging and if so, how do I enable it?

Original source