| Author |
passing a java variable from a JSP to javascript
|
Angus Ferguson
Ranch Hand
Joined: Jun 22, 2012
Posts: 279
|
|
Hi,
I am retrieving a variable from a JSP like this, ${chrome} and it works. Now I have a js script and I want retrieve it from inside
Any idea?
Thanks
|
 |
Jayesh A Lalwani
Bartender
Joined: Jan 17, 2008
Posts: 1319
|
|
What you can is declare a java script variable that is generated by the JSP. Something like this
Let's say the value of chrome in Java is Hello World, the HTML generated will be
You can use the javascript chrome variable in your java script.
|
 |
Angus Ferguson
Ranch Hand
Joined: Jun 22, 2012
Posts: 279
|
|
I am getting the chrome value from a the request.
Any idea?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56521
|
|
Angus Ferguson wrote:I am getting the chrome value from a the request.
This sentence does not parse.
Please read this article to understand why JavaScript has not access to server0side JSP variables. All you can do is what has already been outlined: create markup on the server that's sent to the client for interpretation.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Angus Ferguson
Ranch Hand
Joined: Jun 22, 2012
Posts: 279
|
|
Any example of that, please?
Thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56521
|
|
|
A perfect example has already been posted by Jayesh.
|
 |
 |
|
|
subject: passing a java variable from a JSP to javascript
|
|
|