title: Users should see chat messages from other users without having to refresh the screen
body: <p>I am creating a web chat application using JSP, Servlets, &amp; HTML.  How do I get one user's to get new messages from other user's without a refresh/reload?</p>
  
  <p>I have tried some AJAX but it is not working correctly.</p>
  
  <pre><code>&lt;body&gt;
     &lt;h2&gt;Chat Messages&lt;/h2&gt;
      &lt;div class="myBox"&gt;
   &lt;table&gt;
    &lt;tr&gt;
  &lt;th&gt;user&lt;/th&gt;
  &lt;th&gt;message&lt;/th&gt;
  &lt;th&gt;time&lt;/th&gt;
    &lt;/tr&gt;
      &lt;%  //set the messages into an arraylist
  ArrayList &lt;Message&gt; msgs = new ArrayList&lt;Message&gt;();
  msgs = (ArrayList) request.getAttribute("messages");
  String str = "my name";
  System.out.println("str is of type " + str.getClass().getName());
  
  System.out.println("Message is of type " + 
        msgs.get(0).getClass().getName());
  for(Message mess : msgs)
  {
      %&gt;
      &lt;tr class = "container"&gt;
      &lt;td&gt;&lt;%=mess.getFname() %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%=mess.getMessage() %&gt;&lt;/td&gt;
      &lt;td class="time-right"&gt;&lt;%=mess.getTime() %&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;%
  }
  %&gt; 
    &lt;/table&gt;
     &lt;/div&gt;
  
  
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      //get the session
      HttpSession session = request.getSession();
      String chatId;
      //if they do not have a the session for the chat, then set it
      System.out.println(request.getMethod());
      if(request.getMethod() == "GET"){
          System.out.println("Thats a get");
      }
      else{
          System.out.println("Thats not a get");
      }
  
      //if they accessed this with a get, meaning they chose it from their chats
      //session.getAttribute("roomID")  == null
      if(request.getMethod() == "GET"){
          chatId =  request.getParameter("room");
          session.setAttribute("roomID",chatId);
          System.out.println("the room is " + chatId);
      }
      //otherwise its just a refresh because they posted a message
      else{
          System.out.println("the room was not null");
          chatId = (String) session.getAttribute("roomID");
          System.out.println("The room id is " + chatId);
      }
      System.out.println("The chat that you are in now is " + chatId);
      ArrayList&lt;Message&gt; msgs = DBmanage.getMessages(chatId);
  
      //set that array list into the request and forward to the JSP
      request.setAttribute("messages", msgs);
      request.getRequestDispatcher("/html/Chatroom.jsp").forward(request, response);
  
  }
  </code></pre>
  
  <p>The message gets sent but the to the database but any other users need to refresh before they see any new messages. 
  The ajax isn't working, truthfully probably because I am not fully understanding the correct syntax.
  I am completely stuck and need this for a school assignment!!!
  Thank you so much for any help!</p>