KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > servlet > SessionInspectorServlet


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.servlet;
10
11 import java.io.IOException JavaDoc;
12 import java.io.PrintWriter JavaDoc;
13 import java.util.Enumeration JavaDoc;
14
15 import javax.servlet.ServletException JavaDoc;
16 import javax.servlet.http.HttpServlet JavaDoc;
17 import javax.servlet.http.HttpServletRequest JavaDoc;
18 import javax.servlet.http.HttpServletResponse JavaDoc;
19 import javax.servlet.http.HttpSession JavaDoc;
20
21 /**
22  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
23  * @version $Revision: 1.2 $
24  */

25 public class SessionInspectorServlet extends HttpServlet JavaDoc
26 {
27
28    protected void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp) throws ServletException JavaDoc, IOException JavaDoc
29    {
30       doPost(req, resp);
31    }
32
33    protected void doPost(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp) throws ServletException JavaDoc, IOException JavaDoc
34    {
35       HttpSession JavaDoc session = req.getSession();
36       String JavaDoc id = session.getId();
37       resp.setContentType("text/html");
38       PrintWriter JavaDoc writer = resp.getWriter();
39       writer.print("<html><body>");
40       writer.print("session ID " + id + "<br/>");
41       for (Enumeration JavaDoc e = session.getAttributeNames();e.hasMoreElements();)
42       {
43          String JavaDoc key = (String JavaDoc)e.nextElement();
44          Object JavaDoc 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