How can I share a variable or object between two or more Servlets?

后端 未结 6 1185
星月不相逢
星月不相逢 2020-11-28 21:32

I would like to know if there is some way to share a variable or an object between two or more Servlets, I mean some \"standard\" way. I suppose that this is not a good prac

6条回答
  •  抹茶落季
    2020-11-28 22:00

    Here's how I do this with Jetty.

    https://stackoverflow.com/a/46968645/1287091

    Uses the server context, where a singleton is written to during startup of an embedded Jetty server and shared among all webapps for the life of the server. Can also be used to share objects/data between webapps assuming there is only one writer to the context - otherwise you need to be mindful of concurrency.

提交回复
热议问题