JSP 信息页面调试助手

发布于 2024-11-17 23:36:10 字数 123 浏览 2 评论 0原文

是否有人使用 jsp 调试帮助程序页面,可以将其放入任何 web 应用程序中或包含在另一个 jsp 页面中来查看 header、req 和 session 属性?

如果可能的话可以分享一下吗?这将对许多人有很大的帮助

Does anyone has uses jsp debug helper page that can be dropped into any webapp or included from within another jsp page to view header, req and session attributes?

can you please share if possible ? It will be a great help for many

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

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

发布评论

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

评论(2

岁月无声 2024-11-24 23:36:10
  • pageDebugger.jsp 放入您的 webapp
  • 直接访问页面或从另一个 jsp 中包含 layout.jsp 以在每个页面上显示此详细信息
  • 此页面在表格中列出以下内容
    • 请求参数
    • 页面范围的属性和值
    • 请求范围属性和值
    • 会话范围的属性和值
    • 应用程序范围的属性和值
    • 请求标头
    • 范围内定义的所有 Spring beans
    • 在类路径上搜索资源的选项
  • 对 spring 框架的依赖是可选的如果您不使用

pageDebugger.jsp

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<style type="text/css">
td {
    word-wrap: break-word;
}
</style>
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0"
    style="table-layout: fixed;">
    <colgroup>
        <col width="500">
    </colgroup>
    <tr>
        <th colspan="2">
        <h3>attributes in $paramValues</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${paramValues}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><c:forEach var="item" items="${entry.value}"
                varStatus="status">
                <pre><c:out value="${item}" /></pre>
                <c:if test="${not status.last}">
                    <br />
                </c:if>
            </c:forEach></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $requestScope</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${requestScope}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><pre><c:out value="${entry.value}" /></pre></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $sessionScope</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${sessionScope}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><pre><c:out value="${entry.value}" /></pre></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $pageScope</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${pageScope}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><pre><c:out value="${entry.value}" /></pre></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $headerValues</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${headerValues}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><c:forEach var="item" items="${entry.value}"
                varStatus="status">
                <pre><c:out value="${item}" /></pre>
                <c:if test="${not status.last}">
                    <br />
                </c:if>
            </c:forEach></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $applicationScope</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${applicationScope}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><pre><c:out value="${entry.value}" /></pre></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>System Properties</h3>
        </th>
    </tr>
    <tr>
        <th>Key</th>
        <th>Value</th>
    </tr>
    <%@page import="java.util.Map"%>
    <%@page import="java.util.Set"%>
    <%@page import="java.util.Properties"%>
    <%@page import="java.util.Arrays"%>
    <%
        Properties p = System.getProperties();
        Set<Map.Entry<Object, Object>> set = p.entrySet();
        for (Map.Entry<Object, Object> e : set) {
    %>
    <tr>
        <td><%=e.getKey()%></td>
        <td><%="".equals(e.getValue()) ? " " : e.getValue()%></td>
        <%
            }
        %>
    </tr>
    <tr>
        <th colspan="2">
        <h3>Spring Beans</h3>
        </th>
    </tr>
    <%@page import="org.springframework.web.context.WebApplicationContext"%>
    <%@page
        import="org.springframework.web.context.support.WebApplicationContextUtils"%>
    <%@page import="org.springframework.core.io.Resource"%>
    <%
        try {
            WebApplicationContext springContext = WebApplicationContextUtils
                    .getWebApplicationContext(config.getServletContext());
            if (springContext != null) {
                String[] beanNames = springContext.getBeanDefinitionNames();
                Arrays.sort(beanNames);
                for (String beanName : beanNames) {
                    String className = springContext.getType(beanName)
                            .getName();
    %>
    <tr>
        <td><%=beanName%></td>
        <td><%=className%></td>
    </tr>
    <%
        }
    %>
    <tr>
        <th colspan="2">
        <h3>Spring Resources</h3>
        </th>
    </tr>
    <tr>
        <th colspan="2">
        <form><input name="resources" size="50"/></form>
        </th>
    </tr>

    <%
        String resourceNames = request.getParameter("resources");
                if (resourceNames != null) {
                    Resource[] resources = springContext
                            .getResources(resourceNames);
                    for (Resource r : resources) {
    %>
    <tr>
        <td><%=r.getFilename()%></td>
        <td><%=r.getURI()%></td>
    </tr>
    <%
        }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    %>


</table>
</body>
</html>

请将其删除此外,如果您可以选择修改 web.xml,看看这些也可用于监视/配置活动 http 会话属性

http ://code.google.com/p/sessionmon/

http://messadmin.sourceforge.net/< /a>

  • Drop pageDebugger.jsp in you webapp
  • Access the page directly or include from another jsp like, layout.jsp to show this details on every page
  • This page Lists following in a table
    • Request Parameters
    • Page scoped attributes and values
    • Request scoped attributes and values
    • Session scoped attributes and values
    • Application scoped attributes and values
    • Request headers
    • All Spring beans defined in the scope
    • Option to search for a resource on the classpath
  • Dependency on spring framework is optional remove it if you dont use

pageDebugger.jsp

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<style type="text/css">
td {
    word-wrap: break-word;
}
</style>
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0"
    style="table-layout: fixed;">
    <colgroup>
        <col width="500">
    </colgroup>
    <tr>
        <th colspan="2">
        <h3>attributes in $paramValues</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${paramValues}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><c:forEach var="item" items="${entry.value}"
                varStatus="status">
                <pre><c:out value="${item}" /></pre>
                <c:if test="${not status.last}">
                    <br />
                </c:if>
            </c:forEach></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $requestScope</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${requestScope}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><pre><c:out value="${entry.value}" /></pre></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $sessionScope</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${sessionScope}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><pre><c:out value="${entry.value}" /></pre></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $pageScope</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${pageScope}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><pre><c:out value="${entry.value}" /></pre></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $headerValues</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${headerValues}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><c:forEach var="item" items="${entry.value}"
                varStatus="status">
                <pre><c:out value="${item}" /></pre>
                <c:if test="${not status.last}">
                    <br />
                </c:if>
            </c:forEach></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>attributes in $applicationScope</h3>
        </th>
    </tr>
    <c:forEach var="entry" items="${applicationScope}">
        <tr>
            <td><c:out value="${entry.key}" /></td>
            <td><pre><c:out value="${entry.value}" /></pre></td>
        </tr>
    </c:forEach>
    <tr>
        <th colspan="2">
        <h3>System Properties</h3>
        </th>
    </tr>
    <tr>
        <th>Key</th>
        <th>Value</th>
    </tr>
    <%@page import="java.util.Map"%>
    <%@page import="java.util.Set"%>
    <%@page import="java.util.Properties"%>
    <%@page import="java.util.Arrays"%>
    <%
        Properties p = System.getProperties();
        Set<Map.Entry<Object, Object>> set = p.entrySet();
        for (Map.Entry<Object, Object> e : set) {
    %>
    <tr>
        <td><%=e.getKey()%></td>
        <td><%="".equals(e.getValue()) ? " " : e.getValue()%></td>
        <%
            }
        %>
    </tr>
    <tr>
        <th colspan="2">
        <h3>Spring Beans</h3>
        </th>
    </tr>
    <%@page import="org.springframework.web.context.WebApplicationContext"%>
    <%@page
        import="org.springframework.web.context.support.WebApplicationContextUtils"%>
    <%@page import="org.springframework.core.io.Resource"%>
    <%
        try {
            WebApplicationContext springContext = WebApplicationContextUtils
                    .getWebApplicationContext(config.getServletContext());
            if (springContext != null) {
                String[] beanNames = springContext.getBeanDefinitionNames();
                Arrays.sort(beanNames);
                for (String beanName : beanNames) {
                    String className = springContext.getType(beanName)
                            .getName();
    %>
    <tr>
        <td><%=beanName%></td>
        <td><%=className%></td>
    </tr>
    <%
        }
    %>
    <tr>
        <th colspan="2">
        <h3>Spring Resources</h3>
        </th>
    </tr>
    <tr>
        <th colspan="2">
        <form><input name="resources" size="50"/></form>
        </th>
    </tr>

    <%
        String resourceNames = request.getParameter("resources");
                if (resourceNames != null) {
                    Resource[] resources = springContext
                            .getResources(resourceNames);
                    for (Resource r : resources) {
    %>
    <tr>
        <td><%=r.getFilename()%></td>
        <td><%=r.getURI()%></td>
    </tr>
    <%
        }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    %>


</table>
</body>
</html>

Additionally if you have option to modify web.xml, have a look at these that can also be used to monitor / profile active http session attributes

http://code.google.com/p/sessionmon/

http://messadmin.sourceforge.net/

鸠书 2024-11-24 23:36:10

在工作中,我使用 JDeveloper 从 IDE 以调试模式运行应用程序。您可以在 .jsp 中插入断点并查看所有调试信息。虽然我不是 jdeveloper 的忠实粉丝,但它是 IDE 的一个很好的功能。

At work I have used JDeveloper to run an application in debug mode from the IDE. You can insert breakpoints into your .jsp and view all the debugging info. Although, I am not a big fan of jdeveloper, it is a nice feature of the IDE.

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