Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refreshing a jsp page periodically

 
Rijutha Natarajan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The meta tag will not cause session variables to be lost if the URL specifies the same web app.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the meta tag is rather 1998. Why aren't you pursing a more modern solution via Ajax?
 
Rijutha Natarajan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What specifically is being updated? Text fields? Text in spans?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, am updating text boxes.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks a lot. I will try it and get back
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic