Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

how to retreive the ServletRequest time

Thread view: 
srini.vinod@gmail.com - 13 Jan 2008 17:15 GMT
Hi,

I'm working a servlet and I'm trying to get the date of a
HttpServletRequest. I have tried using the getHeader(),
getDateHeader() and no use... I tried to get the list of header names
and printed it, the output was:

accept

referer

accept-language

accept-encoding

user-agent

host

connection

cookie

I'm not able to find any header related to date or time... Please help
me sort this out... I've been breaking my head for three days now...

Regards,
Vinod
Arne Vajhøj - 13 Jan 2008 17:28 GMT
> I'm working a servlet and I'm trying to get the date of a
> HttpServletRequest. I have tried using the getHeader(),
[quoted text clipped - 12 lines]
> I'm not able to find any header related to date or time... Please help
> me sort this out... I've been breaking my head for three days now...

The browser does not send time.

You will have to just grab the current time at the server.

Arne
Lew - 13 Jan 2008 19:37 GMT
>> I'm working a servlet and I'm trying to get the date of a
>> HttpServletRequest. I have tried using the getHeader(),
[quoted text clipped - 16 lines]
>
> You will have to just grab the current time at the server.

Even if the browser did send time, you couldn't rely on it.  Server time is
the way to go.

Signature

Lew

srini.vinod@gmail.com - 13 Jan 2008 21:52 GMT
> > srini.vi...@gmail.com wrote:
>
[quoted text clipped - 26 lines]
>
> - Show quoted text -

If I use the server time, how will I be able to know the client
machine time zone... What if the client is in a different timezone
from server...
Arne Vajhøj - 13 Jan 2008 23:00 GMT
>>> srini.vi...@gmail.com wrote:
>>>> I'm working a servlet and I'm trying to get the date of a
[quoted text clipped - 18 lines]
> machine time zone... What if the client is in a different timezone
> from server...

You will not.

If you really need to know the time on the client then you will
need to do some JavaScript stuff to explicit submit it to the
server.

Arne
Lew - 13 Jan 2008 23:20 GMT
>>>> srini.vi...@gmail.com wrote:
>>>>> I'm working a servlet and I'm trying to get the date of a
[quoted text clipped - 25 lines]
> need to do some JavaScript stuff to explicit submit it to the
> server.

Even then, you cannot be certain that the time on the client is correct, or
even in the correct time zone.

Why do you need the client time zone anyway?

Why not just store all times in UTC?

Signature

Lew
This post contains two requests for information.

Arne Vajhøj - 13 Jan 2008 23:54 GMT
>>>>> srini.vi...@gmail.com wrote:
>>>>>> I'm working a servlet and I'm trying to get the date of a
[quoted text clipped - 29 lines]
> Even then, you cannot be certain that the time on the client is correct,
> or even in the correct time zone.

No. But it should indicate what the client system is set to.

> Why do you need the client time zone anyway?

That must be for the original poster to answer.

> Why not just store all times in UTC?

Client time would be bad for that purpose.

But I don't think anyone has said anything about storing the
time as a timestamp.

Arne
Lew - 14 Jan 2008 00:06 GMT
Lew wrote:
>> Why do you need the client time zone anyway?

> That must be for the original poster to answer.

That would be whom I was asking, natch.

Signature

Lew

srini.vinod@gmail.com - 14 Jan 2008 02:57 GMT
I'm trying to develop a servlet that displays a map and the time
offset of selected timezone with client time zone...
I tried using javascript, assigned the value to a hidden field, when I
tried to access the value from a servlet, it is null...
Arne Vajhøj - 13 Jan 2008 22:58 GMT
>>> I'm working a servlet and I'm trying to get the date of a
>>> HttpServletRequest. I have tried using the getHeader(),
[quoted text clipped - 19 lines]
> Even if the browser did send time, you couldn't rely on it.  Server time
> is the way to go.

Depends on whether he need server or client time.

Arne
Daniel Dyer - 13 Jan 2008 23:10 GMT
>>>> I'm working a servlet and I'm trying to get the date of a
>>>> HttpServletRequest. I have tried using the getHeader(),
[quoted text clipped - 22 lines]
>
> Arne

He can ask the client for the time, but what if the client tells him it's  
1973?

He could look up the IP address with one of those services that locates it  
geographically and then determine the timezone from that, but that's not  
reliable either (e.g. if there is a proxy involved).

An alternative to doing this on the server, though no more reliable, is to  
do whatever time-related stuff needs to be done on the client using  
JavaScript (if possible).

Dan.

Signature

Daniel Dyer
http://www.uncommons.org

Stanimir Stamenkov - 13 Jan 2008 23:19 GMT
Sun, 13 Jan 2008 23:10:43 -0000, /Daniel Dyer/:

> He can ask the client for the time, but what if the client tells him
> it's 1973?

He can ask the client for a time-zone, instead.  And he could use a
default of some predefined time-zone for the country (if any) of the
first locale returned from |ServletRequest.getLocales()|.

Signature

Stanimir

Lew - 13 Jan 2008 23:26 GMT
> Sun, 13 Jan 2008 23:10:43 -0000, /Daniel Dyer/:
>
[quoted text clipped - 4 lines]
> default of some predefined time-zone for the country (if any) of the
> first locale returned from |ServletRequest.getLocales()|.

Which, like all client-provided information, has to be viewed as likely or
possibly correct rather than certainly correct.

Signature

Lew

Lew - 13 Jan 2008 23:24 GMT
Lew wrote:
>>>  Even if the browser did send time, you couldn't rely on it.  Server
>>> time is the way to go.

Arne Vajhøj wrote:
>> Depends on whether he need server or client time.

> He can ask the client for the time, but what if the client tells him
> it's 1973?

This is not such a far-fetched notion.  Maybe not years off, but I've seen
problems answered on Usenet that had to do with machines being set up in a
different time zone from what its owners think they'd set up, much less what
someone with no operational control at all could guarantee.

The bottom line is that you cannot trust the clock of the client, neither its
correctness nor that it is set for the correct timezone.

This is fine if you don't care what the time is at the client, but only what
the client machine asserts.  In that case it's a mistake to think of the
information as a timestamp, rather view it as a time-formatted arbitrary value.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.