• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

array from jsp to JavaScript

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have to pass an array from a jsp scriplet to a JavaScript function.
In jsp array is populated by items collecting from database.Then I have to pass it to javascript and retrieve those items within JavaScript.
How can I do that?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The simple answer is that you can't. The JSP runs on the server to create the HTML page, and then the Javascript runs on the client. There can be no direct passing of the data from one to the other. (See this article for more information.)

But what you can do is to use the JSP to construct an equivalent Javascript construct on the page that the Javascript code can reference.
[ January 12, 2007: Message edited by: Bear Bibeault ]
 
Soumya Ghosh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I construct an equivalent Javascript construct on the page that the Javascript code can reference?
Can you please tell this using a small demo code?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will not write the code for you. You will learn more that way. But I will help you along.

Let's say it's a string array. In Javascript, a string array could be constructed with:



So you'll need to write code in your JSP to construct such syntax using the elements in the Java array.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic