How Getting Request time ?

Gehirnmann
Gehirnmann used Ask the Experts™
on
How can I get the exact time the request from the client was send to the script?
I DON'T want a server side time! I want something like a parameter from the Request that give the information.
I also DON'T want a client side javascript function to get the time, because this is NOT exact and NOT the time it was send: Example: press refresh on your browser after ten minutes on the response page: is still the old time!

Anyone an answer?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mick BarryJava Developer
Top Expert 2010

Commented:
Try:

Date sent = new Date(request.getDateHeader("Date"));
Mick BarryJava Developer
Top Expert 2010

Commented:
Scratch that, it's a part of the response not the request.

Looking at the request I don't see any details of the time sent so u may have to pass it yourself. In which case i'm not sure if it'll work in cases like if refresh is hit.

Commented:
your logs should reflect the time the request came in at.

CJ
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Author

Commented:
Hmm, that sounds good.
Are the logs available as global variable to read? Or just as file? I mean: does the Server provide an object that gives me information about the time?-- that would be a professional way to do it.
Mick BarryJava Developer
Top Expert 2010

Commented:
I thought you didn't want the server time?

Commented:
well your webserver logs should tell you the time the request arrived to at the webserver.

Can you tell us what webserver you are using?

CJ
server log is still server time.

when user click on submit button, use javascript get the time at that moment and then submit the form back.

Author

Commented:
I'm actually using servlets and JRUN, but should be the same principle. I didn't found an extra forum for that.

But you are right, the log is servertime. I tested that.
But I thought that ALL packages arriving at a machine have timestamps. I should be possible to get these times, because they are definetly client-side times.
Mick BarryJava Developer
Top Expert 2010

Commented:
I can't see a timestamp in the http requests sent from my browser.
>>But I thought that ALL packages arriving at a machine have timestamps.

If you are talking about TCP/IP packet, I'm not sure about that but I don't think there is one.

If you mean HTTP, NO.

>>I'm actually using servlets and JRUN
this doesn't stop you from using javascript, is there any reason so you cannot use javascript at all? otherwise I think my suggestion will sure get you client time.
Mick BarryJava Developer
Top Expert 2010

Commented:
> is there any reason so you cannot use javascript at all?

read the question :)
>>read the question :)
did read again, understood :)

just curious to know the use case, i mean if you don't mind

Author

Commented:
Hey guys:
thank you for your help, but I think there is no TRUE way to do it, I did it now this way:

I have two scripts:
1.
building up jsp page that should never be refreshed with a timestamp from the server (Yes, thats what I do).
2.
building up the next html page with sending the timestamp + the duration of time on the client side.

What happens?
The second script compares the current time with the time that was produced as sum of "old time + duration". if this time is +/- 5 sec. different from the current time-- nothing will happen.. nothing will be executed!

works really good! NO MORE DOUBLE PAYMENTS :-)

and thank you "objects" for trying to understand my question ;-)

Commented:
if your end goal was to remove double payments (like people hitting submit or reload too many times) you could have take a session state route.

You keep track of what state the user is in in the current flow.  Each submission updates the state.  Each request checks the state.  If the state in session is the same as the state that would be set by the request don't do anything, otherwise execute and update the state.  In other words, implement a Transaction Controller Architecture.  We created such a controller that is used in all our our transactions (esp multi-page/step transactions)

CJ
>>We created such a controller that is used in all our our transactions
right! in fact, jakarta Struts has build-in support for this type of control. That's why I asked about use case. I'm interest because I never saw such requirement before.
Distinguished Expert 2018

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- To be PAQed and points NOT refunded.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
Commented:
PAQed - no points refunded (of 200)

modulo
Community Support Moderator

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial