• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create a Clock with Servlets

 
Andreas Müller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi volks,
i am new to servlets&jsp. currently written my first servlet, which display the current Time hh:mm:ss.
When i reload the page, i see the same time. After 60-90 ss, the time become updated.

Is it possible to create a "Clock" with a servlet, which displays continuous time?
like hh:mm:ss with an Update every secound?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets are not the best choice for this; they run on the server and you probably want a technology that runs in the client such as JavaScript.
 
Andreas Müller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, to pass the work of updating the time is better done by the client -> JavaScript, that was my first thought, after postig

My secound thought/question "is this possible with servlet anyway?" just for fun.

Multiple call of

concatanates the time values...

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Once the servlet sends the response to the client, it's done.
 
Andreas Müller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, but sending continously a response to the client like:



could be a way? or "can i show something on a website, and then show something else replaceing the the first thing showed"?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

Once again, the servlet sends the response to the client. Finito. Done. Gone. The end. Period.

Any client-side machinations after that must be initiated by the client.
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, you can send continious response, but to do that, you will need to get a continious request (in your case - refreshing the browser all the time)...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zandis Murāns wrote:Yeah, you can send continious response, but to do that, you will need to get a continious request (in your case - refreshing the browser all the time)...

That is not "continuous".
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that depends on how accurate you do this refreshing. :rolling:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're just muddying the topic with semantics. There is no way that the OP can continuously update the display using the same servlet with some sort of continuous connection.

Polling the server repeatedly via page reload or Ajax is "polling", not "continuous" in the manner that the OP is asking about.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if you look at Javascript clocks, or Swing GUI clocks, they all work by refreshing the display repeatedly. Normally they repeat at intervals of less than a second, but they can't be said to work continuously either.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic