aspose file tools*
The moose likes JSP and the fly likes array from jsp to JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "array from jsp to JavaScript" Watch "array from jsp to JavaScript" New topic
Author

array from jsp to JavaScript

Soumya Ghosh
Greenhorn

Joined: Dec 31, 2006
Posts: 26
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?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61421
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Soumya Ghosh
Greenhorn

Joined: Dec 31, 2006
Posts: 26
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61421
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array from jsp to JavaScript