This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass Array from servlet program to JavaScript

 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I have a question. I write a Java Servlet program to read data from database. I store those data into an array. Then I want pass that array to JavaScript. I also have a select option. My JavaScript will do something according to my selection to display some information from my data array to the other(2nd) select option in the client side browser. That is I want show some information dynamically.
Can I pass an array from Java program to JavaScript? If yes, how?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way to pass data from Java (servlet/JSP) to Javascript is to dynamically generate the JavaScript as if it "always knew" the data. For example
something.jsp:

[ January 28, 2004: Message edited by: Frank Carver ]
 
Jayson Falkner
Author
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Frank's suggestion is the only way to do this. It is important to realize there is no direct connection between objects kept in memory on your server and objects in the client's browser's memory (e.g. JavaScript variables). If you want to dynamically control JavaScript, you are stuck generating the script on your server and sending it off for use in the client's web browser.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about using hidden values in the HTML form and assign the java variables' values into them??? :roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic