Gok Demir
Gok Demir

Reputation: 1402

Identifying which JSP files are running

I work on a huge jsp/servlet project and it has a templating system and it is fairly complex (hard to point which jsp files are imported because it is based on chosen template and some other parameters).When I test the site with web browser I want to identify which jsp file is running without adding debug information to lots of jsp files. How could I do that? Any trick? By the way I use eclipse and tomcat.

Upvotes: 1

Views: 254

Answers (1)

BalusC
BalusC

Reputation: 1108932

Create a Filter which is mapped as follows

<filter-mapping>
    <filter-name>yourFilterName</filter-name>
    <url-pattern>*.jsp</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

and does roughly the following job in the doFilter() method.

String requestURI = ((HttpServletRequest) request).getRequestURI();
String forwardURI = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
String includeURI = (String) request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);

if (includeURI != null) {
    System.out.println("JSP included: " + includeURI);
} else if (forwardURI != null) {
    System.out.println("JSP forwarded: " + requestURI); // No, not forwardURI!
} else {
    System.out.println("JSP requested: " + requestURI);
}

chain.doFilter(request, response);

Upvotes: 2

Related Questions