title: Passing data between two servlets
body: <p>I have two servlets running on the same Tomcat server, and I need to pass data from an instance of one servlet to the corresponding instance of the other servlet.  It appears as though I can do this by doing something like this:</p>
  
  <pre><code>getServletContext().getContext("/path").setAttribute("varName", variable)
  </code></pre>
  
  <p>And I should likewise be able to receive it from the other servlet by using getAttribute.  But, here is my question:</p>
  
  <p>How does the other servlet know when this attribute has been set?  The data can come in at any point in time, and multiple times.  So how do I "notify" the other servlet that there is now data waiting for it to grab?</p>
  
  <p>Thanks,</p>
  
  <p>Eric</p>
  
  <p><b>EDITED:</b></p>
  
  <p>Here is some more insite into what I am trying to do: I am trying to build a chat program with two different apps. There is the client, which can send messages to another app, the chat receiver app. I am using Vaadin for the front-end. The chat receiver app contains two servlets: another Vaadin application, and a basic servlet to receive messages from the client app (this part is already working). Now I want to relay that to the Vaadin application of the chat receiver app, which is in the same war file as the servlet that is receiving the messages. Hopefully that clears things up. Let me know if you think the Vaadin forums would be a better place to post this question. Thank you for your help, I am primarily a core java programmer, so I am pretty confused. I really appreciate it!</p>