Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

auto servlet refresh  RSS feed

 
Bharath Chinnadurai Maharajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question might have been asked some time back in this very forum if so kindly redirect me.
How can i 'Refresh' a servlet automatically every 5 seconds.

Best regards
Bharath Chinnadurai Maharajan
SCJP 1.4
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to initiate this from the client side using either Javascript or the HTML META tag.
 
Bharath Chinnadurai Maharajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isnt there a java way of doing this instead of java script.
I would like to do it in java or Jsp.


Best Regards
Bharath Chinnadurai Maharajan
SCJP 1.4
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A servlet sits and listens for a request and then sends out a response.
Once this request/response cycle has ended, the servlet has no way to connect back to a browser. Thus the term stateless.

If you want to refresh a page, you have to issue a new request. Unless you're running applets, there is no way to do this with Java.
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can send a refresh header, from the servlet. I don't know how widely supported the refresh header is. But, give it a try and let us know!



or



The 60 is the number of seconds to wait and the URL is the page.
[ August 15, 2005: Message edited by: Kerry Wilson ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh! <slap> Good catch Kerry. Yes, setting the header as such is equivalent to using the HTML META mechansim.
 
Bharath Chinnadurai Maharajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx friends,
I will give a try and get back to you
----
bharath chinnadurai maharajan
scjp 1.4
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Doh! <slap> Good catch Kerry. Yes, setting the header as such is equivalent to using the HTML META mechansim.



NOTE: This is still "The client making a new request" and not, as the original poster put it an "auto refresh servlet". Nitpicking?, yes but not understanding the whole request/response nature of web programming often leads to a whole host of other mis-conceptions.
 
Bharath Chinnadurai Maharajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kerry, That worked

This is still "The client making a new request"

Iam a beginner for servlets world, so correct me if iam wrong.
How can this be like a client making a new request. In this method
response.setIntHeader("Refresh", 60) the server reloads the content every 60 seconds. I dont understand where does a client is making a request here.

-----------------------------
Bharath Chinnadurai Maharajan
SCJP 1.4
[ August 15, 2005: Message edited by: Bharath Chinnadurai Maharajan ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That header goes down to the browser with the response.
It is a suggestion that the browser make a request for that URL in n seconds.

All a servlet can do is respond to a request. Once it does, the connection is closed and the servlet is completely unaware of any particular client (browser) until it makes another request.

A great tool for seeing this in action is the LiveHTTPHeaders plugin for Mozilla/Firefox. With it, you can see both the request headers coming from the browser and the response headers coming from the server in real time as they are being made.
http://livehttpheaders.mozdev.org/
[ August 15, 2005: Message edited by: Ben Souther ]
 
Bharath Chinnadurai Maharajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Ben, Now i understood the logic behind this, also the Live Http Headers is a cool one. Guess people like me who are starting servlets could use tools like this for better understanding.

And Ben iam asking just out of curiosity,
I developed a servlet which displays updated time every 2 sec.
I came across in the Live-Http-Header tool some thing like this



It loops on until i close the servlet.
My doubt is what the icon file (favicon.ico) all about. Iam using tomcat 4.1. Again i would like to mention "Just out of curiosity".

-------------------------------
Bharath Chinnadurai Maharajan
SCJP 1.4
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben's point is an important one. Especially in light of the fact that the client can ignore headers at its discretion.

It is the client initiating the new request at the suggestion provided by the servlet in the guise of the header. The servlet engine itself is completely univolved in this activity.

The same goes for headers that suggest that the browser not do any caching.
[ August 15, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With regards to favicon.ico, it's best to open a new topic for new questions rather than tacking them onto the end of an unrelated thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!