One session - many servlets


Web tier: servlets, JSP, Web frameworks: One session - many servlets

  1. One session - many servlets (3 messages)

    How do I get that to work?

    The problem is that I want the information that servlet number one stores to be available from servlet number two and vice versa. Just using getSession doesn't seem to be enough. Should I use the ServletContext in any way to make it work?



    Threaded Messages (3)

  2. One session - many servlets[ Go to top ]

    Storing information in the session should make it shareable to any other servlet/jsp in the same web application during the same session. To share the information to any servlet/jsp in the same web application regardless of a user's session, you can put it in the ServletContext. Just be aware of the threading issues.

    Andy Nguyen
    [email protected]
  3. One session - many servlets[ Go to top ]

    So long as either the user's browser supports cookies or you encode the session id into the URL then you shouldn't have any problems using state between servlets.

    In servlet A:
    request.getSession().setAttribute("Some Key", "Some Value");

    In servlet B:
    String value = (String) request.getSession().getAttribute("Some Key");

    Obviously, the usual NullPointerExceptions should be allowed for etc. etc. but on the whole it is quite straight-forward.

  4. One session - many servlets[ Go to top ]

    servlet work many wonder. power, robust, sped.

    how to loop? switch?