Create a Filter which listens on an url-pattern
of *.jsp
and the INCLUDE
dispatcher only.
<filter>
<filter-name>includeFilter</filter-name>
<filter-class>com.stackoverflow.q2242429.IncludeFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>includeFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
Get the parent page by HttpServletRequest#getServletPath()
and the include page by HttpServletRequest#getAttribute()
with key javax.servlet.include.servlet_path
:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
HttpServletRequest httpreq = (HttpServletRequest) request;
String parentPage = httpreq.getServletPath();
String includePage = (String) httpreq.getAttribute("javax.servlet.include.servlet_path");
// Log it here?
chain.doFilter(request, response);
}