• 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

Servlet Refresh

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would be highly obliged if someone can guide me in refreshing the Servlet page, say after n seconds and also should refreshed when any data is updated .
Also this servlet should be written the data into a FILE so that we can directly access this file itself.
Ratan
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ratan,
Welcome (again) to JavaRanch. We don't have a lot of rules around here, but one of them requires you to use 2 names for your display name (the famous naming policy).
Please take a minute to change your display name here.
You risk getting your account blocked if you continue to ignore these, ahem, friendly reminders :roll: .
[ November 06, 2002: Message edited by: Pauline McNamara ]
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand correctly you would like to display a page to the user and then either after n seconds or when some data changes on the server, refresh that page?
The first can be done using the auto-refresh tag. E.g.
<meta http-equiv="Refresh" content="30">
would repost the page to the servlet after 30 seconds.
The second is not possible. HTTP is a disconnected protocol so there is no way for the server to know which users are currently looking at that page. You could do it using an applet on the client page which opens a socket to the server. Then if the applet could repost the page when it receives notification from the server that some data has changed.
Hope that helps
Jesse
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ratan:

I would be highly obliged if someone can guide me in refreshing the Servlet page, say after n seconds and also should refreshed when any data is updated .
Also this servlet should be written the data into a FILE so that we can directly access this file itself.


Jesse:

The second is not possible. HTTP is a disconnected protocol so there is no way for the server to know which users are currently looking at that page.


I'm not 100% convinced of the impossibility. I envision a thread that polls the data file for changes, resulting in a server-push when a change event happens. Haven't done this myself, but I think it is possible.
Now, as to whether doing this is advisable, that's something else altogether. You would not only have to impliment server-push technology (there is an example in the O'Reilly Servlets book), but you'd also have to be concerned with the thread safety of this approach.
Personally, I'd be inclined to use a database instead of a file.
PCS
 
Jesse Beaumont
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess that would work, under the assumption, that the user does not navigate away in the meantime.
I'd be very wary of this though because all that the server is doing is bundling multiple responses to a single request. If the user navigates away or posts another request in the middle things could get nasty.
Also from what I can tell about the original problem, it seems that this is an indefinate request (i.e. there is no explicit end point other than the server shutting down or the user logging out) so you may run into some thread problems simply because of the number of threads needed to server a minimal number of users (depending on the server implementation)
But I stand corrected...it is possible
Jesse
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic