一直没太搞明白我知道在同一个应用中的不同页面和用户可以用servletContext对象共享数据。但是在不同应用中呢?比如appA,appB在appA中context.setAttribute("name",aaa);在appB中可以取到吗?望高手给详细解答一下,谢谢

解决方案 »

  1.   

    估计不行,应该是同一web app里面的吧。如果像两个工程共用,看来要么写文件,要么写db
      

  2.   

    所以我不太明白他说的全局指的是什么,难道就是指整个应用?比如在tomcat启动的时候会为每个应用创建一个servletContext对象?
      

  3.   

    javax.servlet 
    Interface ServletContext--------------------------------------------------------------------------------public interface ServletContext
    Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file. There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace such as /catalog and possibly installed via a .war file.) In the case of a web application ed "distributed" in its deployment descriptor, there will be one context instance for each virtual machine. In this situation, the context cannot be used as a location to share global information (because the information won't be truly global). Use an external resource like a database instead. The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized. 
      

  4.   

    注意这段:
    In the case of a web application ed "distributed" in its deployment descriptor, there will be one context instance for each virtual machine. In this situation, the context cannot be used as a location to share global information (because the information won't be truly global). Use an external resource like a database instead. 
      

  5.   

    这是sun公司网页的文档
    希望对你有参考
      

  6.   

    看规范,分布式场景不常见,基本不用考虑
    ServletContext就是一个应用一个ServletContext