hi there,
i do have a communication probleme here between my java servlet and an ajax request. more about it:
Absolute path to the index.html (including javascript/ajax request): http://localhost:9080/chat/index.html
In the same folder the servlet: MyChat.class
And the Request is working like this:
var url = "http://localhost:9080/chat";
var name = document.getElementById("username").getAttribute("value"); var message = document.getElementById("message").getAttribute("value");
var tosend = name+","+message;
request.open('GET', url, true); request.send(tosend); request.onreadystatechange = interpretRequest;
I'm having a formular where a user just types in the name and the message and "username" and "message" are tags in my html file. The ajax request works, that's sure, but it doesn't communicate with the servlet. I also don't have an idea where the output from System.out.println() goes. No log file is filled ... And the servlet looks like this:
public class MyChat extends HttpServlet { private static final long serialVersionUID = 1L;
private ArrayList<String> myMessages = new ArrayList<String>();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
BufferedReader r = request.getReader();
while(r.readLine() != null)
{
// split the words at the ','
String[] tmp = r.readLine().split(".\\s");
myMessages.add(tmp[0]+" "+tmp[1]);
}
//response.setContentType("text/html");
PrintWriter out = response.getWriter();
Iterator<String> it = myMessages.iterator();
while(it.hasNext())
{
out.println(it.next());
System.out.println(it.next());
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}