代码之家  ›  专栏  ›  技术社区  ›  chickeninabiscuit

如何确定正在呈现哪些JSP页面?

  •  2
  • chickeninabiscuit  · 技术社区  · 16 年前

    我正在开发一个使用简单JSP的遗留应用程序,它使用 <jsp:include> .

    没有使用任何框架——只是JSP servlet和过滤器。

    有人能建议一种跟踪正在呈现的JSP页面的方法吗?

    可能有一个日志,或者渲染引擎中有一个钩子(Jasper)。

    1 回复  |  直到 16 年前
        1
  •  2
  •   BalusC    16 年前

    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() HttpServletRequest#getAttribute() 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);
    }
    
    推荐文章