识别哪些 JSP 文件正在运行

发布于 2024-10-24 01:46:16 字数 178 浏览 0 评论 0原文

我从事一个巨大的 jsp/servlet 项目,它有一个模板系统,并且相当复杂(很难指出导入了哪些 jsp 文件,因为它基于所选的模板和一些其他参数)。当我使用 Web 浏览器测试站点时我想确定哪个 jsp 文件正在运行,而不向大量 jsp 文件添加调试信息。我怎么能这么做呢?有什么窍门吗? 顺便说一下我用的是eclipse和tomcat。

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 because 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来日方长 2024-10-31 01:46:16

创建一个 Filter ,其中映射如下

<filter-mapping>
    <filter-name>yourFilterName</filter-name>
    <url-pattern>*.jsp</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

,并在 doFilter() 方法中大致执行以下工作。

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文