1

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.

WilliamN
  • 89
  • 11
  • 1
    What are you trying to archive? – Stefan Jan 29 '15 at 11:10
  • I want to export a google chart in a pdf file and when I creating an image of my chart (in JS) the URL of it is long of more than 20.000 caracter so I can't pass it to my export page in the URL (And I have 4 chart to export ...) – WilliamN Jan 29 '15 at 12:55
  • You could create the [chart on server](http://code.google.com/p/googlechartwrapper/) side too. – Stefan Jan 29 '15 at 13:10
  • @stefan I can't create my charts on server side, in this case I have just 4 charts but I want to use the PDF export with my chart on a lot of jsp page who contain charts so I can't remake all of them. – WilliamN Jan 29 '15 at 13:23

2 Answers2

0

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/

  • Their web app is written in Java. Why should they use PHP? – Brandon Jan 29 '15 at 13:23
  • Thanks Brandon, I wanted to write this ;) I just want to pass the value between two JSP page (one where the javascript code is execute and create my var and the other who generate My PDF file) – WilliamN Jan 29 '15 at 13:42
0

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.

Community
  • 1
  • 1
egellon
  • 260
  • 1
  • 9