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

后端 未结 6 1183
星月不相逢
星月不相逢 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 21:44

    Couldn't you just put the object in the HttpSession and then refer to it by its attribute name in each of the servlets?

    e.g:

    getSession().setAttribute("thing", object);
    

    ...then in another servlet:

    Object obj = getSession.getAttribute("thing");
    

提交回复
热议问题