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

后端 未结 6 1182
星月不相逢
星月不相逢 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:41

    Another option, share data betwheen contexts...

    share-data-between-servlets-on-tomcat

      
      
    

    On myApp1:

      ServletContext sc = getServletContext();
      sc.setAttribute("attribute", "value");
    

    On myApp2:

      ServletContext sc = getServletContext("/myApp1");
      String anwser = (String)sc.getAttribute("attribute");
    

提交回复
热议问题