File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Automatic Servlet Refreshing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Automatic Servlet Refreshing" Watch "Automatic Servlet Refreshing" New topic
Author

Automatic Servlet Refreshing

Prabhu Chandrasekaran
Ranch Hand

Joined: Oct 14, 2000
Posts: 36
Friends,
I want to know as to how a servlet can be automatically refreshed after a given amount of time. The data shown in the servlet should be automatically updated as and when the database is updated.
Advance Thanks.
------------------
hanumanth reddy
Ranch Hand

Joined: Jun 12, 2000
Posts: 118
hi,
if you wan tto refresh the servlet after a certian amount of time then use redirect() method with the amount of time to refresh

<a href="http://www.jobklub.com" target="_blank" rel="nofollow">http://www.jobklub.com</a><br /> 'Add Job To Life'
Prabhu Chandrasekaran
Ranch Hand

Joined: Oct 14, 2000
Posts: 36
hi hanumanth,
can you give me a piece of code to explain?
As for as I know, Redirects are given along with an URL for which the redirect is to be done.
Thanks,

------------------
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Prabhu,
Jason Hunter explains 2 techniques for this kind of auto refresh requirements. 1. Client pull and 2. Server Push.
Client pull - means the client (the browser) automatically makes a request for every *** seconds period.
Server push - means the server sends the reponse automatically to the browser.
I grabbed the code for client pull from Jason Hunter's site for you. This example shows , the client makes a request to every 10 secs to a servlet automatically and diplays the time. See it online here. http://www.servlets.com/servlet/ClientPull
Here is the code. For the other tech (Server push) please go through the examples and find out. I try to post when I come across that. Here is the examples link http://www.servlets.com/jsp/examples/index.html
regds
maha anna
Frank Lin
Ranch Hand

Joined: Jan 26, 2001
Posts: 76
Did anyone try the server push? I tried it on both Websphere and Tomcat, but only the last portion was shown. Is there anything on the server side(servelt engine) that is holding up the flush() which can be changed in the setting?
Thanks.
Hema Menon
Ranch Hand

Joined: Oct 29, 2000
Posts: 569
Frank/Prabhu,
Here's the link for server push from Jason Hunter's Java Servlet programming book.
http://www.servlets.com/servlet/Countdown
The source is available at this link http://www.servlets.com/jsp/examples/ch06/index.html
Try Example 6-12
Hmenon

~hm
Frank Lin
Ranch Hand

Joined: Jan 26, 2001
Posts: 76
I knew it works on Jason's server. According to him, it is running on Java Web Server 1.1. I just could not run the same example on Tomcat nor on Websphere. Just wonder if anyone has tried it on newer servlet engines.
Hema Menon
Ranch Hand

Joined: Oct 29, 2000
Posts: 569
Frank,
I haven't tried it yet. Hence I am not sure whether it works on any other servers. In Jason's book, he says that server push is not supported by IE(which version?), and is to be avoided if possible since it is found to be harmful for the server's available socket count. I tried the servlet(On Jason's webserver) on IE 5.5 and Netscape 4.73. It worked perfectly on Netscape. But IE did not recognize the type and the result was not expected.
Thanks,
HMenon
Ash
Greenhorn

Joined: Apr 18, 2000
Posts: 6
I tried this with J2EE and it works.
One thing that i didn't get though is with ie the response appears one below the another while in netscape the lines seems to refresh showing just the one line at a time..
Any information on this will be appreciated....
[This message has been edited by Ash (edited February 15, 2001).]
 
Don't get me started about those stupid light bulbs.
 
subject: Automatic Servlet Refreshing