This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Refresh

 
Badari Nath
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • 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 ]
 
Jesse Beaumont
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • 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
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic