我正在使用使用<jsp:include>
嵌套的简单JSP的遗留应用程序。
没有使用任何框架 - 只是JSP Servlet和过滤器。
有人可以建议一种方法来跟踪正在呈现的JSP页面吗?
也许在渲染引擎(Jasper)中有一个日志,或者一个钩子。
答案 0 :(得分:2)
创建一个过滤器,该过滤器仅监听url-pattern
*.jsp
和INCLUDE
调度程序。
<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>
按HttpServletRequest#getServletPath()
获取父网页,使用密钥javax.servlet.include.servlet_path
按HttpServletRequest#getAttribute()
获取包含页面:
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);
}