Is there a way to have a variable initinalized in Java and then passed to javascript to be modified then sent back for Java to save in a file??
Announcement
Collapse
No announcement yet.
Java to Javascript and back
Collapse
X
-
What kind of variable? If it's a String or number then embed the java variable in js like this
<script type="text/javascript">
var str = "<%=stringInJava%>";
str += " modified in Javascript";
</script>
Then put the value of str in a hidden field and then submit the page for the server to access it.
or if you want to do it in the background while the page is loaded, then you can use the image trick.
<script type="text/javascript">
var str = "<%=stringInJava%>";
str += " modified in Javascript";
var jsp = new Image();
jsp.src = "saveToFile.jsp?s=" + escape(str);
</script>
Or if you are using a java applet, you can use
JSObject to have a Java to Javascript communication link.
Please explain in more detail if none of them suits your needs.
Comment