1 9 package org.jboss.portal.portlet.servlet; 10 11 import java.io.IOException ; 12 import java.io.PrintWriter ; 13 import java.util.Enumeration ; 14 15 import javax.servlet.ServletException ; 16 import javax.servlet.http.HttpServlet ; 17 import javax.servlet.http.HttpServletRequest ; 18 import javax.servlet.http.HttpServletResponse ; 19 import javax.servlet.http.HttpSession ; 20 21 25 public class SessionInspectorServlet extends HttpServlet 26 { 27 28 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException , IOException 29 { 30 doPost(req, resp); 31 } 32 33 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException , IOException 34 { 35 HttpSession session = req.getSession(); 36 String id = session.getId(); 37 resp.setContentType("text/html"); 38 PrintWriter writer = resp.getWriter(); 39 writer.print("<html><body>"); 40 writer.print("session ID " + id + "<br/>"); 41 for (Enumeration e = session.getAttributeNames();e.hasMoreElements();) 42 { 43 String key = (String )e.nextElement(); 44 Object value = session.getAttribute(key); 45 writer.print(key + " = " + value); 46 if (value != null) 47 { 48 writer.print(" / class = " + value.getClass().getName()); 49 } 50 writer.print("<br/>"); 51 } 52 writer.print("</body></html>"); 53 writer.close(); 54 } 55 } 56 | Popular Tags |