Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

New to Javascript - How to work with a given array in a javascript function  RSS feed

 
antonio alcantara
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody:

I'm trying to draw a map using google visualization. For setting different places in the map, I need to pass an array to the javascript method, but I can't get it working

This is the code I'm trying to use


If I put it that way, I get the next error:

Error: missing ] after element list

Line: 122, Column: 34
Source Code:
var list=[Ljava.lang.String;@129efd0;

Does anybody know how can I store in a local array variable in javascript the value of the array in j? I've spent a lot of time googling it but I haven't got anything

Thank you very much in advance
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that Javascript runs in the web browser, while the variable you're trying to look at exists in the Java code generated from the JSP, which runs on the server; by the time the Javascript runs, the Java variable no longer exists. What you need to do instead is write Java code to explicitly generate a Javascript array out of the Java array data. The Java code will run on the server when the page is executed, and it should create the proper Javascript code to initialize a Javascript array containing the same elements. That Javascript code will be embedded in the page, and it will be downloaded to the browser and executed there.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to understand how JSPs operate.
 
antonio alcantara
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help. Now I know a little more about JSP

Just in case another one has the same problem, here is the solution

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