简体   繁体   English

如何将javascript值设置为jslt变量?

[英]How can I set a javascript value into a jslt variable?

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) 我在一个jsp页面中绘制了一个Google图表,我想在一个jslt变量中设置一个javascript变量的值(我不确定我能否做到这一点)

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 ! 我知道javascript是由浏览器生成的,因此我认为不可能在我的jsp中使用javascript var,但是如果您有什么想法可以帮助我,那应该是完美的!

Thanks in advance ! 提前致谢 !

You cannot do this, JSTL is executed on the server side while JavaScript is executed on the client side. 您无法执行此操作,JSTL在服务器端执行,而JavaScript在客户端执行。

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. 另一方面,您应该考虑如何使用该值,如果需要在客户端使用它,则不需要JSTL,您已经在JS中拥有了它,并且可以编写所需的任何脚本。

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 另一方面,如果需要服务器端的值,则需要发送ajax请求,并将该值作为参数放置在可从页面访问的范围中,然后可以在响应中将其用作JSTL变量

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? 在此问题下, 如何使用Servlet和Ajax很好地概括了您如何在Java Web中从Ajax开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM