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?
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?
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.
Find the actual Java code that implements this tag and check if there are any logging statements in it. If there are enable the class in your logging configuration. If there are no logging statements use AOP to define method interceptor which will log every invocation of Java implementation method. From a method interceptor you have access to invoked method arguments and if needed these can be logged as well.
Bear in mind that AOP may slow down the execution of your application. You may want to disable it in the production environment.
There is no simple way to achieve this. My solution was a small file pre.jsp
which contains:
<%@page import="org.apache.log4j.Logger"%>
<%
String __jspName = this.getClass().getSimpleName().replaceAll("_", ".");
Logger log = Logger.getLogger(this.getClass().getName());
log.info("BEGIN JSP "+__jspName);
%>
<!-- BEGIN <%=__jspName %> -->
In every file, I'd then add this line at the beginning:
<%@ include file="/pre.jsp" %>
and this one at the end:
<!-- END <%=__jspName %> --><% log.info("END JSP "+__jspName); %>
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")