home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 November / PCWorld_2000-11_cd.bin / Komunik / sambar444 / _SETUP.1 / SessionInfo.java < prev    next >
Text File  |  1999-08-28  |  3KB  |  78 lines

  1. package sysadmin;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import javax.servlet.*;
  6. import javax.servlet.http.*;
  7.  
  8.  
  9. public class SessionInfo extends HttpServlet
  10. {
  11.     public void init(ServletConfig config)
  12.         throws ServletException
  13.     {
  14.         super.init(config);
  15.     }
  16.  
  17.     public void service(HttpServletRequest req, HttpServletResponse res)
  18.         throws ServletException, IOException
  19.     {
  20.         // Only the Sambar System Administrator may run this servlet
  21.         String isAdmin = (String)req.getAttribute("isSambarAdmin");
  22.         if (isAdmin == null)
  23.             return;
  24.  
  25.         res.setContentType("text/html");
  26.         PrintWriter out = res.getWriter();
  27.         
  28.         out.println("User Name: " + req.getRemoteUser() + "<br>");
  29.         out.println("Authorization Type: " + req.getAuthType() + "<br>");
  30.         out.println("<br><br>");
  31.         out.println("Here are all the current sessions:<br> ");
  32.         HttpSession session = req.getSession(true);
  33.         HttpSessionContext context = session.getSessionContext();
  34.         Enumeration ids = context.getIds();
  35.         out.println("<table border=1 cellpadding=0 cellspacing=0>");
  36.         out.println("<tr>");
  37.         out.println("<td align=middle><font size=-1><b>Session ID</b></font></font></td>");
  38.         out.println("<td align=middle><font size=-1><b>Values</b></font></font></td>");
  39.  
  40.         out.println("<td align=middle><font size=-1><b>New Session</b></font></font></td>");
  41.         out.println("<td align=middle><font size=-1><b>Created</b></font></font></td>");
  42.         out.println("<td align=middle><font size=-1><b>Last Accessed</b></font></font></td>");
  43.         out.println("</tr>");
  44.  
  45.         while (ids.hasMoreElements())
  46.         {
  47.             out.println("<tr>");
  48.             String id = (String)ids.nextElement();
  49.             out.println("<td align=middle><font size=-1> "+id +" </font></td>");
  50.             HttpSession foreignSession = context.getSession(id);
  51.             String sessions[] = foreignSession.getValueNames();
  52.             out.print("<td align=middle><font size=-1>");
  53.  
  54.             for(int s = 0; s < sessions.length; s++)
  55.                 out.print(sessions[s] +", ");
  56.  
  57.             out.println("</font></td>");
  58.  
  59.             if(foreignSession.isNew())
  60.                 out.println("<td align=middle><font size=-1>Y</font></td>");
  61.             else
  62.                 out.println("<td align=middle><font size=-1>N</font></td>");
  63.  
  64.             out.println("<td align=middle><font size=-1>" + 
  65.                 new Date(foreignSession.getCreationTime())+"</font></td>");
  66.             out.println("<td align=middle><font size=-1>" + 
  67.                 new Date(foreignSession.getLastAccessedTime())+"</font></td>");
  68.  
  69.             out.println("</tr>");
  70.         }
  71.  
  72.         out.println("</table>");
  73.         session.invalidate();
  74.         out.flush();
  75.         out.close();
  76.     }
  77. }
  78.