Thats interesting that you say that, cause I'm using ajax.
But thats why I was trying to do this.
I'm basically building a chat application.
I use ajax to send request to servlet, which waits for a data to be added, then printouts the added data.
So there is loop in the servlet like
so while that loop runs, entering message on jsp page, sends another call to same servlet by ajax with the message as a requestParameter
The data on Servlet is updated.
So at this point there are 2 threads from servlet, the one thats waiting, and the one that sent the message.
The one that sent the message doesn't need to do out.println(...), as the waiting thread can do this.
So both threads should return about the same time, one with "", and one with the a message.
But it only seems to show "" in the jsp page.
I was thinking it might be because they are both returning at the same time.
Which is why I was trying to upload the message data from button instead of posting it to servlet.
it works if I get both threads to return something, but doing that, when a new message is sent by user, shouldnt the same message be printed twice in the html, which it doesn't if you see what I mean.
I need a way for the clients front end page (jsp page) to be updated when another client enters text.
I suppose their is RMI, but thats sounds too complicated, and it probably wont work.
How else can I do it?
By nature, HTTP is a request/response protocol. You cannot change that. You'll need to do what everyone else on the web does: either poll using Ajax for changes, or adopt a server-push technology such as Comet (and be sure to have the heavy infrastructure to support it).
Bear Bibeault wrote:What is it that you think that loop is doing for you? It can't return any response. Perhaps you are not showing the whole picture?
Perhaps the missing part of the picture is that "checkIfDataAdded()" has side effects, such as writing to the response. That isn't what the name of the method suggests, but it wouldn't be the first misnamed method ever to be written. To do that would require some gyrations for the method to get a reference to the response, but that wouldn't be impossible either.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop