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 b开发者_JAVA技巧ecause 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.
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);
精彩评论