I am building a chat application using JSP, Servlets and Ajax with Smack API. Once the user connects to Gtalk his buddies list should be displayed onto the UI. I am able to get the buddies list onto console but populating it on the JSP is giving problems.
In my servlet I get the buddy list using:
Roster roster = connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
for(RosterEntry r:entries)
{
String user = r.getUser();
pw.println(user);
}
In my jsp page I want the buddy list to be populated on page load:
$(document).ready(function() {
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.status == 200)
{
document.getElementById(buddies).innerHTML=xmlhttp.responseText;
}
}
}
xmlhttp.open("POST","LoginIMServlet",true);
xmlhttp.send(null);
}
)
<table>
</tr>
<tr>
<td>
<form name=ListForm>
<select id="buddies" name="buddies" size=40 multiple onclick="window.open("ChatWindow.jsp",width=500,height=350,resizable=yes")>
</select>
</form>
</td>
</tr>
</table>
I am not able to populate the multi selector box. How can I solve this?