• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to get client's date and time in servlet

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i am working on an website that will be accessed by users along different timezones. As a requirement of the website, i need to get the client's date and time at the server side. Similarly, i need to convert server's date into client's date before sending any date related information to the client.

I have seen getLocale() method of HttpServletRequest but it doesn't provide any information about client's date and time....

Can anybody help....

Regards,
Akash.
[ March 22, 2006: Message edited by: Akash Abrol ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
See to Trace the information about a client you can use the following

request.getremoteport.

try with this... but i'm not exactly know about the date and time. you use the above thing and search in google, u may get some ideas. All the best

regards...
P.karthikeyan
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use java script and a hidden variable to store and retrurn the date. But in case the customisation is required on the first page that is accessed them it might be difficult with using servlets only.
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can try using the request.getDateHeader("Date") ;
this is, however, normally only used by browsers on a
put or post request, and is, even then, optional, so
for the most part, it probably will not be there.
Otherwise, javascript and a hidden field in forms would
be the way to go. If it is not a form, but a link, then
javascript for a little url rewriting (?date=date) would
also work. Both are defeated by having javascript
turned off though. In general, clients "should" attempt
to provide as little data about themselves as possible,
which makes it hard to get this kind of data.
[ March 22, 2006: Message edited by: Martin Simons ]
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few other ways.

You could include a small applet on the page which reads the time from the browser and sends it direct to the server.

What most time-sensitive applications do, though is to use a cookie containing a time offset from server time. Typically the web application might try to read the cookie on each communication from a client browser - if the cookie is absent, redirect to a "whast time is it?" page, then set the cookie based on the answer before forwarding to the real destination page. Much like login, really.

A combination of the two approaches above would look for the cookie, if the cookie is not found, send a page containing a small applet which sends back the client time, then the web app sets the cookie based on the message from the applet. Almost magic, and no URL-rewriting or JavaScript needed!
 
Akash Abrol
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any other way of getting client's date and time EXCEPT JavaScript or Cookies. The date and time information is very critical for my application. So i dont want to rely on Javascript or Cookies.

Regards,
Akash.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think it is possible to get reliable answer without using Javascript.
There is nothing to worry about Javascript, since majority of applications on the web are not possible without using Javascript.
With advent of new web technologies, Javascript has to be supported by browser.

So I think you can safely rely on it.

Have a initial home page which will be accessed and sent to the browser.
On that page write java script code on onload function.

window.location.href = "http://yourlocation/myactualhome?date="+ new Date();

This will redirect to you actual home page and you can get the date and time as parameter.

May be this helps.
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Though you can but it not a very nice of doing it.

Get the IP for the request. Find to which geographic region it maps to and change the time accordingly.

But I guess that applets or the Javascript method is better.
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic