Dumping an HTTP session for debugging

Below is Java code to dump an HTTP session for debugging.

    /**
     * Dump all of the available session attributes, for debugging.
     * @param session HTTP session for which to dump attributes
     */
    private static void dumpSession(HttpSession session) {
        System.out.println("Session reference: " + session);
        System.out.println("Session attributes:");
        Enumeration attributeNames = session.getAttributeNames();
        while (attributeNames.hasMoreElements()) {
            String attributeName = (String) attributeNames.nextElement();
            Object value = session.getAttribute(attributeName);
            System.out.println("   --> " + attributeName + " = " + value);
        }
    }

DumpHttpSession (last edited 2010-05-28 17:01:16 by KennethPronovici)