4

I'm working on a legacy application that is using simple JSPs that are nested using <jsp:include>.

No frameworks are being used - just JSP Servlets and filters.

Can anyone suggest a way to trace which JSP pages are being rendered?

Perhaps there's a log, or maybe a hook in the rendering engine (Jasper).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
chickeninabiscuit
  • 9,061
  • 12
  • 50
  • 56

1 Answers1

2

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);
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555