aspose file tools*
The moose likes Servlets and the fly likes Servlet Refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Refresh" Watch "Servlet Refresh" New topic
Author

Servlet Refresh

Badari Nath
Greenhorn

Joined: Jul 11, 2002
Posts: 6
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

Joined: Jan 19, 2001
Posts: 4012
    
    6
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

Joined: May 30, 2002
Posts: 43
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


---<br />Time flies like an arrow,<br />Fruit flies like a banana
Philip Shanks
Ranch Hand

Joined: Oct 15, 2002
Posts: 189
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


Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Jesse Beaumont
Ranch Hand

Joined: May 30, 2002
Posts: 43
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Refresh