This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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 ]
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
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.
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!
Joined: May 30, 2002
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