Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class my_Servlet extends HttpServlet implements HttpSessionListener
- {
- String User_Id;
- static Vector<String> Valid_User_Id_Vector=new Vector<String>();
- private static int activeSessions=0;
- public void sessionCreated(HttpSessionEvent se)
- {
- // associate User_Id with session Id;
- // add User_Id to Valid_User_Id_Vector
- Out(" sessionCreated : "+se.getSession().getId());
- activeSessions++;
- }
- public void sessionDestroyed(HttpSessionEvent se)
- {
- if (activeSessions>0)
- {
- // remove User_Id from Valid_User_Id_Vector by identifing it's session Id
- Out(" sessionDestroyed : "+se.getSession().getId());
- activeSessions--;
- }
- }
- public static int getActiveSessions()
- {
- return activeSessions;
- }
- public void init(ServletConfig config) throws ServletException
- {
- }
- public void destroy()
- {
- }
- protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
- {
- User_Id=request.getParameter("User_Id");
- }
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- processRequest(request, response);
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- processRequest(request, response);
- }
- public String getServletInfo()
- {
- return "Short description";
- }
- }
- public void sessionCreated(HttpSessionEvent se) {
- Vector ids = (Vector) se.getSession().getServletContext().getAttribute("currentUserIds");
- //manipulate ids
- }
- static String User_Id;
- protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
- {
- HttpSession session=request.getSession(true);
- Add_User_Id(session.getId(),request.getParameter("User_Id"););
- }
- static void Add_User_Id()
- {
- assiciate [Session_Id , User_Id] in a map
- }
- static void Remove_User_Id(String Session_Id)
- {
- Valid_User_Id_Vector.remove(User_Id ) by looking it up in a [Session_Id , User_Id] map
- }
- public void sessionCreated(HttpSessionEvent se)
- {
- activeSessions++;
- }
- public void sessionDestroyed(HttpSessionEvent se)
- {
- if (activeSessions>0)
- {
- My_Servlet.Remove_User_Id(se.getSession().getId());
- activeSessions--;
- }
- }
Add Comment
Please, Sign In to add comment