Link to home
Start Free TrialLog in
Avatar of eaglesview
eaglesview

asked on

automatic refresh of a jsp page

hi all,
I have a problem regarding refreshing a jsp page. The first time I call the jsp file, the data from the database is displayed correctly. But when I update the DB, and call the jsp page, the data displayed in the browser is not updated. I still have to press "ctrl-r" to update the display. How would I update the display in the browser without using "ctrl-r"?

thanks.
ASKER CERTIFIED SOLUTION
Avatar of pellep
pellep
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually, the best thing that works in IE and Netscape is to have the following:
<%
response.addHeader("Pragma" , "No-cache") ;
response.addHeader("Cache-Control, "no-cache") ;
response.addDateHeader("Expires", 0);  
%>

BOTH in the head of the of page and bottom of the page (I read this in a message board and it seems
to work for me)

<html>
<head>
<%
// this prevents caching in NS and IE
response.addHeader("Pragma" , "No-cache") ;
response.addHeader("Cache-Control, "no-cache") ;
response.addDateHeader("Expires", 0);  
%>
<!-- this will refresh the page every 5 seconds -->
<META HTTP-EQUIV=Refresh CONTENT="5; URL=currentJSP.jsp"/>
</head>
<body>

....

</body>
<%
// this helps prevent caching in IE
response.addHeader("Pragma" , "No-cache") ;
response.addHeader("Cache-Control, "no-cache") ;
response.addDateHeader("Expires", 0);  
%>
</html>

Also what you can do is add a random number at the end of the URL when you do the meta refresh.

HTH,
CJ
Avatar of raid999
raid999

you can also set a timer in the JSP page and then use response.redirect(URL);
Avatar of eaglesview

ASKER

thanks.. it solved my problem.