File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to have the same timer on all pages?

 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends

i am developing a project in which i have a sidebar with a time elapsed timer on it.
which on click get started and on stop record the elapsed time to database, working fine.

Now the problem is that when user is on home page start the timer it start running but as you move on any other page there will
new unstarted timer.
I am using <jsp:include> to include that side bar with timer, on my pages.
Can any body please guide me to solve this problem.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to persist the timer value in the session so that it can be shared across requests.
 
william blake
Greenhorn
Posts: 9
Chrome Eclipse IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You'll need to persist the timer value in the session so that it can be shared across requests.



Bear Bibeault's way is correct
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my jsp code


and this is javascript which get called onclick


now in this how can i use session ??? :-\
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you thought of? What have you tried?

If the timer value is going to be persisted on the server in the session, how would you initialize it? How would you get the current value when a page loads?

 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually what i want to code is, when a button get clicked a timer get started which calculates and show the elapsed time to user,
when user wants he click the button(indication that he finished the job) timer get stopped and record the time in database.
now as because i am displaying it with javascript which is get changing per second how can i manage it with session attribute.
How to change the session value every second.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really need to change it on the server every second? Think about it.
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i just want to display a timer i want this change to take place on page only and just store the final elapsed time on server in database.
Problem is only that i explained in my first post of this topic.

There is always a new timer for each page.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you store the timer info in the session, all pages can "share" the same timer. (Not really, but if each timer on each page is in synch, it looks like a single timer.)

My point is that you don't need to keep changing the timer value in the session. Think about it -- I mean really think about it. What information would you need to store in the session to know how to create a timer on each page that has the same value as all the others, without having to keep updating the session?

By the way, is this a count-down or a count-up timer?
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
count up timer
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so given that you always know what time is is now, what other single piece of information would you need to know in order to compute the current value of the timer?
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to find a way out ...i could pickup current time, but i want to show elapsed time only.
Still don't have clear idea how to do this efficiently, trying to think on :-/
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say that "right now" is exactly 10:00 -- if you want to know how much time has elapsed for a timer that was started earlier, what one piece of information do you need to know about that timer?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic