Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging every jsp:include

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?

like image 525
Thilo Avatar asked Jul 01 '26 05:07

Thilo


2 Answers

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")

like image 135
axtavt Avatar answered Jul 03 '26 19:07

axtavt


Not directly, but you could write your own tags. If you're sufficently crazy and industrious, you can write <thilo:include> tags that do <jsp:include> and call up a bit of Java code to do logging via log4j or such.

like image 31
Carl Smotricz Avatar answered Jul 03 '26 20:07

Carl Smotricz