• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to refresh my page?

 
Rich Smyth
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning JSP. I wrote a very simple JSP that displays the time of day. Basically I have
<BODY>
<%@ page import MyClock %>
<%= MyClock.getTime()=%>
</BODY>
where MyClock is a class that uses GregorianCalendar and
getTime() is a static method that returns a String representing the time.
Every time the user invokes my page I would like the time to change but it does not. Any idea what
I'm doing wrong?
 
Rich Smyth
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW in my original post I made a typo: I forgot the quotes around the class name in my import statement!
 
Zac Roberts
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can show us your MyClock class...
 
Zac Roberts
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also what output are you getting... and for one thing, this line
<%= MyClock.getTime()=%>
needs to lose an equals sign like so...
<%= MyClock.getTime()%>
 
Zac Roberts
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and I had a type, you also need a space like this one...
<%= MyClock.getTime() %>
 
Ruilin Yang
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may include a statement in the top of you page:
response.setIntHeader("Refresh",3);
try it.
 
Rich Smyth
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'm dealing with some kind of caching problem? When I use the browser's (IE 5) forward or back buttons to return to my page or I rehit the Go button while my page is displayed, my clock does not update. However when I press the browser's Refresh button the clock DOES refresh.
The earlier suggestion to set the "refresh" header results in the clock being refreshed even if the user does nothing: unfortunately this is not the behavior I need.
thanks
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some HTTP directives that you can put at the top of your JSP page to stop browsers and proxy servers caching it although, off the top of my head, I can't remember what they are.
There's a great answer to this on jGuru, but it seems as if you have to now subscribe to do any kind of searching. :roll:
Lucky that Yahoo! has indexed these pages before!
Here's the link -> http://www.jguru.com/faq/view.jsp?EID=377
HTH
Simon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!