<%@page import="java.io.*" %> <%@page import="java.util.*" %> <%! /* Copyright(C) 2005 Simon Howard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. JSP Session Browser: displays the contents of your JSP session and allows manipulation. */ void listObjects(HttpSession session, JspWriter out) throws Exception { int elements = 0; out.print(""); out.print(""); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.print(""); out.print(""); out.print(""); out.print(""); out.print(""); ++elements; } out.print("
NameClass
" + name + "" + session.getAttribute(name).getClass().getName() + "x
"); out.print("
"); if (elements > 0) out.println("delete all"); else out.println("(session is empty)"); } void showObjectDetail(HttpSession session, JspWriter out, String name) throws Exception { out.print("

Object: " + name + "

"); out.print("(back)"); out.print("

"); out.print("
"); out.print("
" + session.getAttribute(name) + "
"); out.print("
"); } void deleteAllObjects(HttpSession session) throws Exception { Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); session.removeAttribute(name); } } %>

The amazing JSP session browser

<% String actionType = (String) request.getParameter("action"); String detailName = (String) request.getParameter("name"); if (detailName != null) { if (actionType != null) { if (actionType.equals("delete")) { session.removeAttribute(detailName); out.println(detailName + " removed."); listObjects(session, out); } else if (actionType.equals("deleteall")) { deleteAllObjects(session); listObjects(session, out); } else if (actionType.equals("invalidate")) { session.invalidate(); out.println("Session invalidated."); return; } } else { showObjectDetail(session, out, detailName); } } else { listObjects(session, out); } %>
Session created <%= new Date(session.getCreationTime()) %>. invalidate session