Smack在Java EE中是否工作良好?
|
Smack是否可以在Java EE中正常运行?我在场时遇到问题。
我可以通过doPost方法从登录表单中获取凭据。我可以成功进行身份验证以及连接。getRoster()也可以使用。接下来,我只想显示在线用户,以便在我看到用户时显示在线状态对象为所有用户存储默认值“不可用”,即使这些用户可用也是如此!
整个聊天应用程序在正常的Java类中都没有任何缺陷,没有任何变化。
String userName = request.getParameter(\"username\");
String password = request.getParameter(\"password\");
HttpSession session=request.getSession();
session.setAttribute(\"username\", userName);
SmackAPIGtalkServlet gtalk = new SmackAPIGtalkServlet();
ConnectionConfiguration config = new ConnectionConfiguration(
\"talk.google.com\", 5222, \"gmail.com\");
connection = new XMPPConnection(config);
config.setSASLAuthenticationEnabled(false);
try {
connection.connect();
} catch (XMPPException e) {
e.printStackTrace();
}
try {
connection.login(userName, password);
} catch (XMPPException e) {
e.printStackTrace();
}
System.out.println(connection.isAuthenticated());
boolean status = connection.isAuthenticated();
if (status == true) {
gtalk.displayOnlineBuddyList();
response.sendRedirect(\"Roster.jsp\");
}
else
{
response.sendRedirect(\"Failed.jsp\");
}
}
public void displayOnlineBuddyList() {
Roster roster = connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
int count1 = 0;
int count2 = 0;
for (RosterEntry r : entries) {
Presence presence = roster.getPresence(r.getUser());
if (presence.getType() == Presence.Type.unavailable) {
// System.out.println(user + \"is offline\");
count1++;
} else {
System.out.println(name+user + \"is online\");
count2++;
}
}
roster.addRosterListener(new RosterListener() {
// Ignored events public void entriesAdded(Collection<String>
// addresses) {}
public void entriesDeleted(Collection<String> addresses) {
}
public void entriesUpdated(Collection<String> addresses) {
}
public void presenceChanged(Presence presence) {
System.out.println(\"Presence changed: \" + presence.getFrom()
+ \" \" + presence);
}
@Override
public void entriesAdded(Collection<String> arg0) {
// TODO Auto-generated method stub
}
});
}
我对此感到困惑,无法使代码与servlet一起使用。有人可以帮我吗?
没有找到相关结果
已邀请:
3 个回复
漂汀拦
倾坞髓
捐焦