To assign the value of a JavaScript variable into Java variable
I have encountered a situation where I have to assign the value of a JavaScript variable into Java variable. Please suggest me a way to do it.
P.S: Assigning value of Java variable into JavaScript is something like this:
< Script>< %
String str = "abcd";
%> var x = &l开发者_JS百科t;%= a %>; /Script>
I have to do opposite of it.
If Java is being used as the server-side language, by the time the page has been sent, Java has long finished (it doesn't run after the page has loaded). You may make a request to a page, sending the variable with the request, and that page may have Java handle the variable, though.
It is not even clear what you are doing, but I assume that the snippet you show is part of a template for a web page. You will not be able to get the variable directly - JavaScript will be running on another computer some continents apart!
But you can make the client communicate with the server, using AJAX.
精彩评论