Read Browser/Client time from Http Servlet request header

空扰寡人 提交于 2019-12-23 10:11:25

问题


Is it possible to read the Browser(Client machine) time when a request is made to the servlet?


回答1:


I don't believe so. Unfortunately the HTTP Date header is only sent for PUT or POST messages, and even then it's optional:

Clients SHOULD only send a Date header field in messages that include an entity-body, as in the case of the PUT and POST requests, and even then it is optional. A client without a clock MUST NOT send a Date header field in a request.

If you have control of the client, you could (perhaps) encode it as a separate experimental HTTP header. Or add it as a GET parameter etc.




回答2:


You can use javascript and append the time to every request. Provided that javascript is enabled, you can add the following to your links:

link = link + "?date="+(new Date()).getTime()

You can do something similar, if you need timezone information. This question may help.



来源:https://stackoverflow.com/questions/1199545/read-browser-client-time-from-http-servlet-request-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!