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?
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.
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.
servlet work many wonder. power, robust, sped.
how to loop? switch?