How can I pass data from a servlet running in one context (webapp) to a servlet running in another context?
Created May 4, 2012
Ryan Breidenbach There are three ways I can think of off the top of my head:
- Store the information you want to share in a persistant format, such as in a file system or database. That way, any servlet that is running in a JVM that can "see" these resources can get to this information.
- If persisting this information is not an option, you can bind this information to a context that is accessible to all servlet contexts, such as the application server's context. This way, you can keep the data you want to share in memory.
- Use the old fashion way of passing information to a servlet - HTTP. One servlet could foward a request to another servlet and include the data that needs to be shared as parameters in the request.
[See also http://www.jguru.com/jguru/faq/view.jsp?EID=50791]