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 !

1
  • 1
    Learn about Ajax or form submissions to send the data back to the server. Commented Jan 26, 2015 at 12:50

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, I've never used ajax so if you have some example it will be perfect :)
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.