• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AJAX requests on page reload

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have a JSP page page on which I am running some AJAX functions. ie. on page load, an AJAX function which queries the JSP page for the value of a String called currentMessage starts running. This works very well and displays the current value of the String currentMessage as I have requested it to do.

The problem arises when I reload the JSP page using my browsers refresh button or reload. In the beginning of my JSP code, I set the value of currentMessage to "", which is basically an empty string. But even when I reload the page, thinking that everything has started anew, the value of currentMessage still remains the last value it was set to before the page reload. How can I make sure that the value of currentMessage is reset each time the page reloads. Thanks.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should recall the function. Is it possible to see some code.

Eric
 
igwe kalu kalu ogba
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, first here is the javascript:



CounterThread ensures that the get method is run every 2 seconds to get the current value of currentMessage.

In my JSP/Servlet, this gives prints the value of currentMessage:




Of course the value of currentMessage is changed during runtime of the page. But when I refresh the page, shouldn't the page begin with the new value for currentMessage?

Of course, the body element of the HTML component of my JSP page loads the retrieveURL() function once it starts.

Thanks.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try adding an alert message inside your funciton retrieveURL() and see if it is being called when the page is being refreshed. The code looks fine to me.

Eric
 
igwe kalu kalu ogba
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric, just have one more question. The page you're seen is being deployed as a war file. WHen it's just a webapp on tomcat (in a folder) the ajax call works, but if it is deployed in a war file the AJAX calls don't work anymore and nothing is displayed. Looking at the code, is there any way to make AJAX calls work from within a WAR file? THanks.
 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Being deployed as a WAR file shouldn't make any difference whatsoever - after all, Tomcat expands the WAR into a folder anyway. Did you make sure to delete the web-app's folder before you put in a new WAR? Tomcat doesn't usually do that by itself.

And this,

response.setHeader("Cache-Control", "no-cache");

may not be enough. When I want to make absolutely certain the page isn't cached, I do the following:



-Yuriy
[ July 21, 2005: Message edited by: Yuriy Zilbergleyt ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic