How to reload a page on client machine at some server(context) event?
Joined: Apr 15, 2006
This one is really interesting, I have one chat application and so using ServletContext and ServletContextAttributeListener maintaining one vector list of users in context. Whenever new user logs in i want to reload the pages of existing users. I know i have to write the code in attributeReplaced method but what i dont know is what will be the code to reload the pages of existing users.
Practical explanation: When say "TOM" logs in chatter's list shows "Tom". Now suppose "Dick" logs in so on "Dick's" page it shows "Tom" and "Dick", but shows only "Tom" on "Tom's" page. which should show Tom and Dick in list.
I hope it's clear and very simple to get the problem.
I got one solution of META tag but it is too much of overload to load the page say after some interval. especially when i can have an event set for it.
Please have your expert advice.
Thanks in advance Manoj Amrutkar
Joined: Oct 30, 2001
In HTTP Web applications, all requests have to be initiated by the Web client. Therefore, there is no way for the server to force a client to reload, other than as a response to a request from the client.
If you have a Web client that needs to be kept up to date with stuff that is happening on the server, you must poll the server periodically from the client. There is no way around this, within your architecture.
However, you do not need to reload the whole page on every poll. There are a variety of ways of avoiding this. AJAX is the current preference. Suggest you read up on it.
Note that the solution is likely to be almost entirely client-side code, and have little to do with servlets.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
Joined: Jul 25, 2006
Hi Peter Chase there is a way.The method is very very simple.The solution is with the HTML meta tag.
If you add the following code in your HTML page
The client contacts the server for every 3 seconds.i.e the client reloads the current web page for every 3 seconds.You can change the value for the content.If the value for the content is given as 30 then the page refreshes itself for evry 30 seconds.
If you want to automatically reload a particular document after some time then add the following code:-
Here abc.jsp will be automatically reloaded after 15 seconds.
Try it out.Its very simple.
Joined: Feb 03, 2004
well, you are not reacting on a server-side event, you are just asking the server every n seconds if some event occured.
what we want is something that picks up the phone when it rings, and not something which picks up the phone every n seconds and performs a check wether someone _really_ called