在 servlet 和 webservice 之间共享静态对象 [英] Sharing a static object between a servlet and a webservice
问题描述
我有一个处理 http get 请求的 servlet,我希望能够共享一个对象,该对象也被我正在开发的 web 服务使用.它们都在同一个 web-app 容器中的同一个 tomcat 服务器上.我不确定最好的方法是什么?
I have a servlet which handles http get requests that I'd like to be able to share an object which is also used by a webservice im developing. They are both on the same tomcat server within the same web-app container. Im not sure best how to do it any ideas ?
推荐答案
您可以通过将内容作为属性存储在 ServletContext(使用 setAttribute
/getAttribute
).您可以在 ServletContextListener,将其存储在 ServletContext
中,然后检索它并从您的 Web 服务和 servlet 中使用它.
You can share things across the webapp by storing them as attributes in the ServletContext (using setAttribute
/ getAttribute
). You could create the object in an impelementation of ServletContextListener, store it in the ServletContext
, and then retrieve it and use it from your web service and servlet.
这篇关于在 servlet 和 webservice 之间共享静态对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!