Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Digital Clock  RSS feed

 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

I want to make a digital clock without using applets and javascript..Do i have to use servlet thread that i would start in init() method ???

Thanks..
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by robin singal:
HI

I want to make a digital clock without using applets and javascript..Do i have to use servlet thread that i would start in init() method ???

Thanks..


Why not applets or Javascript?
If you do this in a servlet means you are doing it at the server and soon you'll run out of bandwidth because of the number of page requests.
And still its not guaranteed to be in real time.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need a thread or init().

The servlet can return the time each time it called, then you just need a way to get the servlet to refresh repeatedly.
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not applets or Javascript?


Rightly Said.
Actually i was asked to do so & that time i didn't thought about this ..

But if i use jsp which would run on client side would that help ???
 
Mr.Rakesh Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by robin singal:
HI

I want to make a digital clock without using applets and javascript..Do i have to use servlet thread that i would start in init() method ???

Thanks..


Hi Robin,

If you really don't want to make the digital clock using applets and javascript, you can use servlet's init() to initialize that but really that is not the right way of doing this practically.
 
Mr.Rakesh Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by robin singal:


Rightly Said.
Actually i was asked to do so & that time i didn't thought about this ..

But if i use jsp which would run on client side would that help ???
 
Mr.Rakesh Kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by robin singal:


Rightly Said.
Actually i was asked to do so & that time i didn't thought about this ..

But if i use jsp which would run on client side would that help ???


------------------------

No, there is no difference in JSP & Servlet intrenally, JSP is just a convenient & userfrendly way of writing the same thing. With JSP you are not compelled to write the HTML code inside the java, the web-container do all convesion & compilation related for you.
 
arulk pillai
Author
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the client to pull the time every stipulated seconds as shown below, so that your digital clock will refresh every 10 seconds

response.setHeader(�Refresh�, 10);

Refresh does not stipulate continual updates. It just specifies in how many seconds the next update should take place. So, you have to continue to supply �Refresh� in all subsequent responses. The �Refresh� header is very useful because it lets the servlet display a partial list of items or an introductory image to be displayed while the complete results or real page is displayed later (e.g. in 10 seconds). You can also specify another page to be reloaded as follows:

respose.setHeader(�Refresh�, �10;URL=http://localhost:8080/myCtxt/crm.do�);

The above setting can be directly set in the <HEAD> section of the HTML page as shown below as opposed to setting it in the servlet. This is useful for static HTML pages.

<META HTTP-EQUIV=�Refresh� CONTENT=�5; URL=http://localhost:8080/myCtxt/crm.do� />
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David

Ya that comes out to be a issue of Refresh basically...
It means we always have to rely on third party technologies(like ajax,javascript,iframes) when it comes to page refresh (if one dosen't use applets)???

Thanks!!
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rakesh Kumar for the Info!!
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello arulk

Actually i can't even use this setHeader method as i don't want the page to refresh but change the value of clock every second.

Thanks!!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15859
80
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by robin singal:
But if i use jsp which would run on client side would that help ???

JSP pages do not run on the client side, they run on the server, just like servlets.
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by robin singal:
Hello David

Ya that comes out to be a issue of Refresh basically...
It means we always have to rely on third party technologies(like ajax,javascript,iframes) when it comes to page refresh (if one dosen't use applets)???

Thanks!!

If the refresh is set in the response header, the page refreshes at stipulated intervals, and this is taken care by the browser. Why do we need to rely on "third party technologies" for this?
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by robin singal:
Hello arulk

Actually i can't even use this setHeader method as i don't want the page to refresh but change the value of clock every second.

Thanks!!


You could consider setting a refresh at every second, for the clock to display each second. But as already discussed, JSP/Servlet is not the right technology to fulfil such a requirement.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without using any client-side technologies like JavaScript or Ajax (which are not "3rd-party", by the way, they are native to the browser) the only way to effect any change to the page is with a refresh.

So if your requirements include:

1) No JavaScript
2) No refreshing

Your task is impossible.

Is this a homework assignment, or is some crazed project leader trying to drive you crazy?
[ October 24, 2008: Message edited by: Bear Bibeault ]
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for delay as it was a holiday time here... [ ]
Thanks all for the info!!
[ October 31, 2008: Message edited by: robin singal ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!