wood burning stoves 2.0*
The moose likes JSP and the fly likes How to have the same timer on all pages? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to have the same timer on all pages?" Watch "How to have the same timer on all pages?" New topic
Author

How to have the same timer on all pages?

Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

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

Joined: Jan 10, 2002
Posts: 61095
    
  66

You'll need to persist the timer value in the session so that it can be shared across requests.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
william blake
Greenhorn

Joined: Jul 17, 2013
Posts: 9

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

Joined: May 09, 2012
Posts: 100

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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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

Joined: May 09, 2012
Posts: 100

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

Joined: Jan 10, 2002
Posts: 61095
    
  66

Do you really need to change it on the server every second? Think about it.
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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

Joined: May 09, 2012
Posts: 100

count up timer
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

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

Joined: May 09, 2012
Posts: 100

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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to have the same timer on all pages?