Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Class java script Question  RSS feed

 
kavan desai
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can anybody tell whether we can use java class like java.util.ArrayList in javascript ??if yes then how ?? give some example or like if possible.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
Javascript and Java are two different languges (who's names both happen to start with the same four letters) and are executed on two different machines.

You can interate over the array list on the server and print the values as the text of a Javascript array.
 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One point to note however is that you can include java code in your javascript at page creation time. Once the page is written to the clients machine it will see this dynamic code as a static piece of the javascript. I've done this through the use of JSP expression tags. It works something like this:



Just a sidebar.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point is, all the Javascript (as well as the HTML) on the page is just seen as meaningless template text by the JSP processor. Likewise, by the time the page gets to the browser, all of the JSP elements have been executed on the server. So there can be no interaction between the server-side JSP and the client-side Javascript -- they are completely unaware of each other's existence.
[ October 06, 2005: Message edited by: Bear Bibeault ]
 
Mark Wuest
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FWIW, this is where I've been using AJAX like a madman. Ok, I don't use XML.

But I have just a few requests that are essentially just accessors to session objects like arrays and AJAX lets me access them from javascript almost at will. AJAX R0X0RZ!

Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!