aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Refreshing a jsp page periodically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Refreshing a jsp page periodically" Watch "Refreshing a jsp page periodically" New topic
Author

Refreshing a jsp page periodically

Rijutha Natarajan
Greenhorn

Joined: Apr 09, 2012
Posts: 6
I have created a jsp page in which I load a set of text boxes with values from the database. I need to refresh this page every 5 seconds. I tried using the meta tag, but it causes logging out. I am guessing its because the session variables are getting destroyed. Could someone please point me in the right direction? Thanks in advance...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

The meta tag will not cause session variables to be lost if the URL specifies the same web app.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Also, the meta tag is rather 1998. Why aren't you pursing a more modern solution via Ajax?
Rijutha Natarajan
Greenhorn

Joined: Apr 09, 2012
Posts: 6
I tried the following code in the javascript. 'box' is the class of the div tag containing all the text boxes I want to refresh.
But even this is not working. I am very new to java and jsp, so am not sure if what am doing is right or not.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

"not working" isn't helpful (see ItDoesntWorkIsUseless).

And the code you posted is JavaScript and has nothing to do with Java or JSP.

Let's take a step back: what are you really trying to accomplish. Let's ignore the "how" for now, and discuss the "what".
Rijutha Natarajan
Greenhorn

Joined: Apr 09, 2012
Posts: 6
I am trying to implement a simple scheduler. A priority is calculated based on the arrival time and the resources the user wants. All these information are stored in a database. If the resource is busy, then the user waits until its his turn. When the user is waiting a jsp page displays his position in the queue and other related statistics. This is a dynamic data and I want to refresh this part of the data every few seconds.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

What specifically is being updated? Text fields? Text in spans?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

(P.S. This is clearly going to be a JavaScript discussion so I've shuffled this along to a more appropriate forum.)
Rijutha Natarajan
Greenhorn

Joined: Apr 09, 2012
Posts: 6
Yes, am updating text boxes.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

OK, that seems simple enough. How I'd approach it:

  • Set up an interval timer for the period you want.
  • In the timer callback, issue a $.getJson() request to the server.
  • Have the server return a JSON object that contains properties that match the names or ids (whichever works best) of the elements that are to be updated. The property value is the new value of the element.
  • In the success handler, iterate through the properties to set the values of the elements. Use val(), not attr().

  • Rijutha Natarajan
    Greenhorn

    Joined: Apr 09, 2012
    Posts: 6
    Thanks a lot. I will try it and get back
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Refreshing a jsp page periodically