1

I draw a google chart in a jsp page and I want to set the value of a javascript variable in a jslt variable (I'm not sure that I can make it)

I have this :

google.visualization.events.addListener(chart, 'ready', function () {
    chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">'; //I want to have chart.getImageURI() in a jslt var for pass it in parameter
    console.log(chart_div.innerHTML);       
});

And I want to make something like this :

<c:set var="var1" value="myUrl"/> //Where myUrl = chart.getImageURI()

I know that javascript is generated by browser so I think it's not possible to take the javascript var in my jsp but if you have some ideas to help me it should be perfect !

Thanks in advance !

WilliamN
  • 89
  • 11

1 Answers1

1

You cannot do this, JSTL is executed on the server side while JavaScript is executed on the client side.

On the other hand, you should think about how you want to use the value, if you need it on the client side, no need for JSTL, you already have it in JS and you can script whatever is your need.

On the other hand, if you need the value on the server side, you need to send an ajax request with the value as a parameter place in a scope accessible from your page, and than you can use it inside a response as a JSTL variable

A nice digest of how would you start with Ajax in a JAVA web is offer under this question How to use Servlets and Ajax?

Community
  • 1
  • 1
Master Slave
  • 27,771
  • 4
  • 57
  • 55
  • Ok, I've never used ajax so if you have some example it will be perfect :) – WilliamN Jan 26 '15 at 13:24
  • While there's plenty of online material, I've updated with a link to an SO question, which gives quite a good digest. Note that in the examples in the answer the variable is not pushed in JSTL, but its likely that you'll also figure out that you don't need it as well, after going through the examples. Hope it will be helpfull to you – Master Slave Jan 26 '15 at 13:34