title: How do I use Ajax to connect to Java servlets?
body: <p>I am developing a chat client using java. I was able to connect to gtalk as well as chat using SMACK API. Now I need to do the same with jsp servlets and ajax.</p>
  
  <p>I could do the authentication and getting the buddy list with jsp and servlets only. But I have to use Ajax for the chat (so that page won't be refreshed).</p>
  
  <p>for sending and receving msgs I use the api s classes in java. The code is below:</p>
  
  <pre><code>public void sendMessage(String message, String to) throws XMPPException
  {
  Chat chat = connection.getChatManager().createChat(to, this);
  chat.sendMessage(message);
  }
  
  public void processMessage(Chat chat, Message message)
  {
  if(message.getType() == Message.Type.chat)
  System.out.println(chat.getParticipant() + " says: " + message.getBody());
  }
  </code></pre>
  
  <p>Now how do I do the same in Ajax? Can I use the API methods along with ajax? Or use these in servlets and get the response from servlets with ajax and populate the msg s on the page?</p>