Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-20-2008, 12:55 AM   #1
Registered: Sep 2005
Location: kannur
Posts: 59

Rep: Reputation: 15
arraylist in javascript


i have a arraylist in jsp, i need to pass this arraylist to javascript and store there.

For some validations i need to refer this stored arraylist in javascript.
And display some messages to user.

how can i pass arraylist object fron jsp to javscript.
how can i search this arraylist in javascript for some specified value.

waiting for your reply......
Old 03-22-2008, 12:04 PM   #2
LQ Newbie
Registered: Mar 2008
Posts: 11

Rep: Reputation: 0
I don't know JSP, but I do know how to inject server variables into JavaScript. In PHP it would be something like this:
//JavaScript document
$arr = array('Bob', 'Tom', 'Harry');
var arr = <?php echo('[' . implode(',', "'" . $arr . "'") . ']'); ?>;
The function 'echo' writes output to the client; 'implode' puts each array value, surrounded by single-quotes, together with a comma between each consecutive pair. The dots concatenate strings together like a plus-sign does in Java. The output of the above would be:
//JavaScript document

var arr = ['Bob','Tom','Harry'];

Last edited by Jesdisciple; 03-22-2008 at 12:14 PM.
Old 03-23-2008, 05:44 PM   #3
Registered: Mar 2008
Posts: 101

Rep: Reputation: 15
You cannot pass the arraylist object from JSP to JS directly. You need to loop through each value and construct the JS array object.

Here is the sample code snippets.

<script language="javascript">
var tempArr = new Array();
for (int i=0; i<tempArrayList.size(); i++){%>
tempArr[<%=i%>] = <%=(String)tempArrayList.get(i);%>

Fedora Development

Last edited by prad77; 04-17-2008 at 03:23 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort test for an ArrayList (java) thefalling Programming 3 12-02-2006 10:32 PM
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
ArrayList question (Java) ksgill Programming 5 10-14-2003 02:00 PM
Java ArrayList question ksgill Programming 2 10-12-2003 07:54 AM
Help with javascript? BajaNick Linux - Software 2 07-20-2003 08:41 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:47 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration