Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Access timestamp values in JSP javascript  RSS feed

 
Vineeth Vasudevan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an ArrayList of timestamps in the form 2015-02-01 10:05:06,

How can I send this from servlet to JSP and access it in the unload javascript function?
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

This is an old and classical problem. Below, I provide some links. It boils down to date format conversion. Format your date for javascript format (2015-03-25T12:00:00) with a java.text.DateFormat.

https://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html
http://www.w3schools.com/js/js_date_formats.asp

P.S. You could probably simply use String.replace(' ','T') to gain efficiency and save on overhead ;-)




 
Vineeth Vasudevan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OnLoad Javascript*
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vineeth Vasudevan wrote:OnLoad Javascript*


actually, one of the brightest webdev I have recently showed me that you can now replace onload= with:



I found it, and I still find it much more flexible than onload.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A.J. Côté wrote:showed me that you can now replace onload= with:


Not exactly. That's a jQuery ready handler and it is not a direct replacement for the load event, but rather an event that is fired when the DOM has finished being built and is ready to be manipulated.

And it is, of course, only available if jQuery is loaded onto the page. It cannot be used without jQuery.
 
Vineeth Vasudevan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sending the ArrayList from the servlet by using session.setAttribute()..


Can you give me an example of how to handle the dates in the JSP?
thanks

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it that you want to exactly do? Re-create the list for processing by JavaScript code? Embed them as part of the HTML display? Something else?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!