简体   繁体   中英

How can I execute JS on server-side?

I'm on a Java EE project and I need to use the value of a JS var on my Java code but my java code is execute before my JS (logic)

But I need the value of a JS var to execute my java and I think it will work if I execute my js on server-side but I don't know how to do this ...

My code is something like this : JS :

function(){
var url = "an url of 20.000 char that I can't pass in GET and who is automatically generated by google chart API"
}

Java :

<%
String urlChart = "value of my "url" var in js";
session.setAttribute("urlChart", urlChart); 
%>

But I don't know how tu put the value of my JS var un my java code. Can you help me ? Somebody said me that I have to use AJAX but I don't know how to use it.

That is not possible in my understanding. you must switch to some other alternate solutions. you can use CGI or PHP or AJAX. http://www.w3schools.com/ajax/

You can check this similiar question: how to send a string to a servlet from javascript using xmlhttprequest

If this won't help, then you need to provide more details because i'm not sure if i understand your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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