• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing a java variable from a JSP to javascript

 
Isaac Ferguson
Ranch Hand
Posts: 839
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Isaac Ferguson
Ranch Hand
Posts: 839
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the chrome value from a the request.

Any idea?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64724
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Isaac Ferguson
Ranch Hand
Posts: 839
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any example of that, please?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64724
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A perfect example has already been posted by Jayesh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic