Re: Getting the date/time from the client
One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time of the machine the browser is running). Is there any way to accomplish this ? Thanks regards Vinu -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting the date/time from the client
Hi, May be you can use: request.getDateHeader() Have a look at, there is a related thread there: http://www.theserverside.com/discussions/thread.tss?thread_id=38542 Vinu Varghese [EMAIL PROTECTED] wrote: Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time of the machine the browser is running). Is there any way to accomplish this ? Thanks regards Vinu -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org ~Regards, ~~Alireza Fattahi - Try the all-new Yahoo! Mail . The New Version is radically easier to use The Wall Street Journal
Re: Getting the date/time from the client
Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time of the machine the browser is running). Is there any way to accomplish this ? Thanks regards Vinu -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting the date/time from the client
SK, That javascript prints the current client time. But I want the client time with the request. The scenario is : I have a index.jsp %@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleInsert title here/title /head body Client time : a href=clienttime.htm Click/a /body /html and a servlet that can take the client time (Hoping to :-) ) which is mapped to 'clienttime.htm' protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/plain); long time = request.getDateHeader(Date); // Hoping to get the client date. PrintWriter out = response.getWriter(); out.println(Server time + new Date()); out.println(Client time (long) + time); out.println(Client time + new Date(time)); } Is there any way to do this (get the client time from the request) ? Or Am I trying to do a dumb thing ? ;) Thanks Regards Vinu Shinya Koizumi wrote: Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time of the machine the browser is running). Is there any way to accomplish this ? Thanks regards Vinu -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org
Re: Getting the date/time from the client
uh... no luck yet. getDateHeader only returns the date value when you have some query strings in date format. So, send the time as a part of query string like this index.jsp?requesttime=25:40:12 or something similar. If one has a better solution let him know. SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 2:23 AM Subject: Re: Getting the date/time from the client SK, That javascript prints the current client time. But I want the client time with the request. The scenario is : I have a index.jsp %@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleInsert title here/title /head body Client time : a href=clienttime.htm Click/a /body /html and a servlet that can take the client time (Hoping to :-) ) which is mapped to 'clienttime.htm' protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/plain); long time = request.getDateHeader(Date); // Hoping to get the client date. PrintWriter out = response.getWriter(); out.println(Server time + new Date()); out.println(Client time (long) + time); out.println(Client time + new Date(time)); } Is there any way to do this (get the client time from the request) ? Or Am I trying to do a dumb thing ? ;) Thanks Regards Vinu Shinya Koizumi wrote: Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time of the machine the browser is running). Is there any way to accomplish this ? Thanks regards Vinu -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting the date/time from the client
The HTTP spec (rfc2616) says clients should only send the Date header with http messages with body content (POST, PUT) and even then it's optional. Try adding a date string as a parameter on your GET request which your servlet can then parse from request.getParameter(...). One way to do this would be to change your link to a form with a hidden input field for your date value. Add an onclick/onsubmit javascript handler to your form button which sets the value of the hidden field to the current date in a format that your servlet will understand. for example: function setDate(form) { form.dateField.value = new Date().toString(); } Example assumes a hidden form input field with name dateField. HTH, Jon Vinu Varghese wrote: SK, That javascript prints the current client time. But I want the client time with the request. The scenario is : I have a index.jsp %@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleInsert title here/title /head body Client time : a href=clienttime.htm Click/a /body /html and a servlet that can take the client time (Hoping to :-) ) which is mapped to 'clienttime.htm' protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/plain); long time = request.getDateHeader(Date); // Hoping to get the client date. PrintWriter out = response.getWriter(); out.println(Server time + new Date()); out.println(Client time (long) + time); out.println(Client time + new Date(time)); } Is there any way to do this (get the client time from the request) ? Or Am I trying to do a dumb thing ? ;) Thanks Regards Vinu Shinya Koizumi wrote: Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time of the machine the browser is running). Is there any way to accomplish this ? Thanks regards Vinu -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting the date/time from the client
you can get a Locale from the request, and adjust the time accordingly. Vinu Varghese wrote: but that still sets the server date - yes ? Pid wrote: write a filter that activates for that url, and get the time just before you doFilter. if you need to, you can pass the date obj as an attribute Date date = new Date(); hreq.setAttribute(thisIsTheDate, date); chain.doFilter(hreq, hres); Jon Wingfield wrote: The HTTP spec (rfc2616) says clients should only send the Date header with http messages with body content (POST, PUT) and even then it's optional. Try adding a date string as a parameter on your GET request which your servlet can then parse from request.getParameter(...). One way to do this would be to change your link to a form with a hidden input field for your date value. Add an onclick/onsubmit javascript handler to your form button which sets the value of the hidden field to the current date in a format that your servlet will understand. for example: function setDate(form) { form.dateField.value = new Date().toString(); } Example assumes a hidden form input field with name dateField. HTH, Jon Vinu Varghese wrote: SK, That javascript prints the current client time. But I want the client time with the request. The scenario is : I have a index.jsp %@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleInsert title here/title /head body Client time : a href=clienttime.htm Click/a /body /html and a servlet that can take the client time (Hoping to :-) ) which is mapped to 'clienttime.htm' protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/plain); long time = request.getDateHeader(Date); // Hoping to get the client date. PrintWriter out = response.getWriter(); out.println(Server time + new Date()); out.println(Client time (long) + time); out.println(Client time + new Date(time)); } Is there any way to do this (get the client time from the request) ? Or Am I trying to do a dumb thing ? ;) Thanks Regards Vinu Shinya Koizumi wrote: Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time of the machine the browser is running). Is there any way to accomplish this ? Thanks regards Vinu -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org
Re: Getting the date/time from the client
Thanks Pid, I think that is a good idea Let me try - Regards Vinu Pid wrote: you can get a Locale from the request, and adjust the time accordingly. Vinu Varghese wrote: but that still sets the server date - yes ? Pid wrote: write a filter that activates for that url, and get the time just before you doFilter. if you need to, you can pass the date obj as an attribute Date date = new Date(); hreq.setAttribute(thisIsTheDate, date); chain.doFilter(hreq, hres); Jon Wingfield wrote: The HTTP spec (rfc2616) says clients should only send the Date header with http messages with body content (POST, PUT) and even then it's optional. Try adding a date string as a parameter on your GET request which your servlet can then parse from request.getParameter(...). One way to do this would be to change your link to a form with a hidden input field for your date value. Add an onclick/onsubmit javascript handler to your form button which sets the value of the hidden field to the current date in a format that your servlet will understand. for example: function setDate(form) { form.dateField.value = new Date().toString(); } Example assumes a hidden form input field with name dateField. HTH, Jon Vinu Varghese wrote: SK, That javascript prints the current client time. But I want the client time with the request. The scenario is : I have a index.jsp %@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleInsert title here/title /head body Client time : a href=clienttime.htm Click/a /body /html and a servlet that can take the client time (Hoping to :-) ) which is mapped to 'clienttime.htm' protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/plain); long time = request.getDateHeader(Date); // Hoping to get the client date. PrintWriter out = response.getWriter(); out.println(Server time + new Date()); out.println(Client time (long) + time); out.println(Client time + new Date(time)); } Is there any way to do this (get the client time from the request) ? Or Am I trying to do a dumb thing ? ;) Thanks Regards Vinu Shinya Koizumi wrote: Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time of the machine the browser is running). Is there any way to accomplish this ? Thanks regards Vinu -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Vinu Varghese [EMAIL PROTECTED] www.x-minds.org
RE: Getting the date/time from the client
Is that really appropriate?? What if I have my Locale set to France, and my clock set to Pacific Standard Time? Then what? (assume I am on the east coast of the USA...) Tim -Original Message- From: Vinu Varghese [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 8:05 AM To: Tomcat Users List Subject: Re: Getting the date/time from the client Thanks Pid, I think that is a good idea Let me try - Regards Vinu Pid wrote: you can get a Locale from the request, and adjust the time accordingly. Vinu Varghese wrote: but that still sets the server date - yes ? Pid wrote: write a filter that activates for that url, and get the time just before you doFilter. if you need to, you can pass the date obj as an attribute Date date = new Date(); hreq.setAttribute(thisIsTheDate, date); chain.doFilter(hreq, hres); Jon Wingfield wrote: The HTTP spec (rfc2616) says clients should only send the Date header with http messages with body content (POST, PUT) and even then it's optional. Try adding a date string as a parameter on your GET request which your servlet can then parse from request.getParameter(...). One way to do this would be to change your link to a form with a hidden input field for your date value. Add an onclick/onsubmit javascript handler to your form button which sets the value of the hidden field to the current date in a format that your servlet will understand. for example: function setDate(form) { form.dateField.value = new Date().toString(); } Example assumes a hidden form input field with name dateField. HTH, Jon Vinu Varghese wrote: SK, That javascript prints the current client time. But I want the client time with the request. The scenario is : I have a index.jsp %@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleInsert title here/title /head body Client time : a href=clienttime.htm Click/a /body /html and a servlet that can take the client time (Hoping to :-) ) which is mapped to 'clienttime.htm' protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/plain); long time = request.getDateHeader(Date); // Hoping to get the client date. PrintWriter out = response.getWriter(); out.println(Server time + new Date()); out.println(Client time (long) + time); out.println(Client time + new Date(time)); } Is there any way to do this (get the client time from the request) ? Or Am I trying to do a dumb thing ? ;) Thanks Regards Vinu Shinya Koizumi wrote: Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] minds.org To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date/time (ie the time
Re: Getting the date/time from the client
A good devil's advocate question, or was it rhetorical? Either way it's got exactly the answer you'd expect, you'll set the date to whatever Locale the Request returns. Obviously. Tim Lucia wrote: Is that really appropriate?? What if I have my Locale set to France, and my clock set to Pacific Standard Time? Then what? (assume I am on the east coast of the USA...) Tim -Original Message- From: Vinu Varghese [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 8:05 AM To: Tomcat Users List Subject: Re: Getting the date/time from the client Thanks Pid, I think that is a good idea Let me try - Regards Vinu Pid wrote: you can get a Locale from the request, and adjust the time accordingly. Vinu Varghese wrote: but that still sets the server date - yes ? Pid wrote: write a filter that activates for that url, and get the time just before you doFilter. if you need to, you can pass the date obj as an attribute Date date = new Date(); hreq.setAttribute(thisIsTheDate, date); chain.doFilter(hreq, hres); Jon Wingfield wrote: The HTTP spec (rfc2616) says clients should only send the Date header with http messages with body content (POST, PUT) and even then it's optional. Try adding a date string as a parameter on your GET request which your servlet can then parse from request.getParameter(...). One way to do this would be to change your link to a form with a hidden input field for your date value. Add an onclick/onsubmit javascript handler to your form button which sets the value of the hidden field to the current date in a format that your servlet will understand. for example: function setDate(form) { form.dateField.value = new Date().toString(); } Example assumes a hidden form input field with name dateField. HTH, Jon Vinu Varghese wrote: SK, That javascript prints the current client time. But I want the client time with the request. The scenario is : I have a index.jsp %@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleInsert title here/title /head body Client time : a href=clienttime.htm Click/a /body /html and a servlet that can take the client time (Hoping to :-) ) which is mapped to 'clienttime.htm' protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/plain); long time = request.getDateHeader(Date); // Hoping to get the client date. PrintWriter out = response.getWriter(); out.println(Server time + new Date()); out.println(Client time (long) + time); out.println(Client time + new Date(time)); } Is there any way to do this (get the client time from the request) ? Or Am I trying to do a dumb thing ? ;) Thanks Regards Vinu Shinya Koizumi wrote: Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] minds.org To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { long l = request.getDateHeader(Date); Date d = new Date(l); System.out.println(d); } SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 12:51 AM Subject: Getting the date/time from the client Hi All, I am doing a project in jsp/servlet and tomcat, which requires to take the client date
RE: Getting the date/time from the client
I was playing devil's advocate -- since we don't really know the OP's requirement(s), but we do know the OP seemed to really want the client's time. -Original Message- From: Pid [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 6:38 PM To: Tomcat Users List Subject: Re: Getting the date/time from the client A good devil's advocate question, or was it rhetorical? Either way it's got exactly the answer you'd expect, you'll set the date to whatever Locale the Request returns. Obviously. Tim Lucia wrote: Is that really appropriate?? What if I have my Locale set to France, and my clock set to Pacific Standard Time? Then what? (assume I am on the east coast of the USA...) Tim -Original Message- From: Vinu Varghese [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 8:05 AM To: Tomcat Users List Subject: Re: Getting the date/time from the client Thanks Pid, I think that is a good idea Let me try - Regards Vinu Pid wrote: you can get a Locale from the request, and adjust the time accordingly. Vinu Varghese wrote: but that still sets the server date - yes ? Pid wrote: write a filter that activates for that url, and get the time just before you doFilter. if you need to, you can pass the date obj as an attribute Date date = new Date(); hreq.setAttribute(thisIsTheDate, date); chain.doFilter(hreq, hres); Jon Wingfield wrote: The HTTP spec (rfc2616) says clients should only send the Date header with http messages with body content (POST, PUT) and even then it's optional. Try adding a date string as a parameter on your GET request which your servlet can then parse from request.getParameter(...). One way to do this would be to change your link to a form with a hidden input field for your date value. Add an onclick/onsubmit javascript handler to your form button which sets the value of the hidden field to the current date in a format that your servlet will understand. for example: function setDate(form) { form.dateField.value = new Date().toString(); } Example assumes a hidden form input field with name dateField. HTH, Jon Vinu Varghese wrote: SK, That javascript prints the current client time. But I want the client time with the request. The scenario is : I have a index.jsp %@ page language=java contentType=text/html; charset=ISO-8859- 1 pageEncoding=ISO-8859-1% !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1 titleInsert title here/title /head body Client time : a href=clienttime.htm Click/a /body /html and a servlet that can take the client time (Hoping to :-) ) which is mapped to 'clienttime.htm' protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/plain); long time = request.getDateHeader(Date); // Hoping to get the client date. PrintWriter out = response.getWriter(); out.println(Server time + new Date()); out.println(Client time (long) + time); out.println(Client time + new Date(time)); } Is there any way to do this (get the client time from the request) ? Or Am I trying to do a dumb thing ? ;) Thanks Regards Vinu Shinya Koizumi wrote: Vinu Yeah, you are right about it, I can't get getDateHeader working. For the solution one, I have setup like this for jsp and worked. %@ page session=false % html head meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 title%= application.getServerInfo() %/title /head body Current Time: % out.println(SCRIPT LANGUAGE=JavaScript); out.println(var currentTime = new Date();); out.println(document.write(currentTime.toLocaleString());); out.println(/SCRIPT); out.println(/HEAD); % /body /html SK - Original Message - From: Vinu Varghese [EMAIL PROTECTED] minds.org To: Tomcat Users List users@tomcat.apache.org Sent: Tuesday, July 11, 2006 1:24 AM Subject: Re: Getting the date/time from the client Thanks SK, I tried the second solution , but request.getDateHeader(Date) returns -1 . Also I didn't understand the first solution ( embed a javascript), Can u pls elaborate that. Thanks and regards Vinu Shinya Koizumi wrote: One is to embed javascript in the output out.println(HTMLHEADtitleJavaScriptExample/title); out.println(SCRIPT LANGUAGE=JavaScript); out.println(function back() {); out.println(history.back(-1);); out.println(}); out.println(/SCRIPT); out.println(/HEAD); The other solution is to get it from the request header