Reputation: 3331
I'm writing a Servlet Filter which measures http request and response times.
The filter is deployed on Apache Tomcat 7 web server.
I was wondering if there's any way to identify which Servlet or JSP is being called on each request other than parsing the request's URI (and for example, checking for .jsp suffix)?
Upvotes: 3
Views: 531
Reputation: 1108922
Not without changing the servlets/JSPs so that they set a specific request attribute which you in turn get after the FilterChain#doFilter()
call.
I can only give the hint that HttpServletRequest#getServletPath()
is probably a nicer way to obtain the actually requested resource. It does that in a context-independent way so that you don't need to fiddle with getRequestURI()
to trim the context path off. Also, if there's a servlet which is mapped on for example /foo/*
, then this would only return /foo
instead of /foo/bar/baz
. Just in case you're interested.
Since you're using Tomcat, you may be interested in its builtin Access Log Valve which offers you a way to log requests less or more the same way as the well known Apache HTTPD, including the times. This is of course only of interest if you have full admin control over the Tomcat instance.
Upvotes: 4