• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to reload a page on client machine at some server(context) event?

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:-)

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

:-)

jan
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic