开发者

How to determine which JSP pages are being rendered?

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 开发者_Go百科a way to trace which JSP pages are being rendered?

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


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜