Smack在Java EE中的功能是否正常?我遇到了問題。 我通過doPost方法從登錄表單中獲取憑據。我可以成功進行身份驗證,並且connection.getRoster()也可以正常工作。接下來,我只想顯示在線用戶,因此當我得到用戶時,即使存在對象可用,存在對象也會爲所有用戶存儲默認值「不可用」!Smack在Java EE中的工作良好
整個聊天應用工程沒有瑕疵在一個普通的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
}
});
}
我堅持這一點,並沒有能夠得到的代碼servlets..Can人的工作幫助我??
是咂嘴可以很好地用於J2EE至少對我來說。 – 2011-05-24 10:13:31
發佈代碼。它與java-ee無關 – 2011-05-24 10:17:44
@Jigar Joshi編輯了我的問題。你可以看看它 – newbie 2011-05-24 10:26:32