This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes Can you send data from Java variables into JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Can you send data from Java variables into JavaScript" Watch "Can you send data from Java variables into JavaScript" New topic
Author

Can you send data from Java variables into JavaScript

Robert Johnson
Ranch Hand

Joined: Feb 11, 2005
Posts: 32
?


Whats in a name?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

no

But you can write the Javascript with the data embedded.
[ April 07, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kash Mhai
Greenhorn

Joined: Apr 01, 2005
Posts: 29
You can have Java variables passing values into Javascript but not other way round.


-------------<br />There are wheels within wheels...<br />P.G Wodehouse
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12674
    
    5
Are you talking about the server side, writing Javascript from inside a JSP or the client side where Javascript actually executes?
If you mean the server side - I suggest that you start with a mock-up plain HTML page containing Javascript that does what you want, then figure out how to get JSP to write that HTML.
Bill


Java Resources at www.wbrogden.com
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

You can have Java variables passing values into Javascript but not other way round.


No, you can't. They cannot inter-operate in any fashion. But as I stated, Java can be used to generate the Javascript that will eventually be sent to the client. That is not at all the same as "passing Java variables into Javascipt".
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
As it is about "you can". Yes you can.



But you must view that resultant html file. As JSP is server-side technology and javascript is, on the other hand, client-side.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Yes, that is generating Javascript to be sent to the client. There is no "passing" in the Java sense of the term involved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can you send data from Java variables into JavaScript