我如何使用Ajax连接到Java小? [英] How do I use Ajax to connect to Java servlets?

查看:120
本文介绍了我如何使用Ajax连接到Java小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用java开发一个聊天客户端。我能够连接到GTALK以及聊天使用SMACK API。现在我需要用JSP servlet和阿贾克斯这样做。

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.

我可以做认证,获取好友列表与JSP和servlet的唯一。但是,我不得不使用Ajax用于聊天(使页面不会被刷新)。

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).

发送和receving封邮件我用的是API会Java中的类。在code是如下:

for sending and receving msgs I use the api s classes in java. The code is below:

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());
}

现在我该怎么办同样在阿贾克斯?我可以使用API​​方法与阿贾克斯?或者在servlet中使用这些和得到的Servlet使用Ajax响应并填充味精S中的网页上?

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?

推荐答案

看一看 DWR

这篇关于我如何使用Ajax连接到Java小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆