1. Access the value returned by JS in JSP:
Problem:
Copy codeThe Code is as follows:
<Script language = "javascript">
<! --
Var str = "123 ";
<%
String aa;
%>
-->
</Script>
How can I obtain the str value in JAVASCRIPT from aa in this JSP ????
The details are as follows:
Copy codeThe Code is as follows:
<Script language = "javascript">
Function returnValue (){
Var myform = document. form1;
Var str = myform. text1.value;
<%
String aa;
// How can I make aa equal to str in js ???
%>
}
</Script>
<Form name = "form1">
<Input type = "text" name = "text1" onchange = "returnValue ();">
</Form>
Solution:
It must be submitted because one is running on the client and the other is running on the server;
Use a hidden field in jsp
Copy codeThe Code is as follows:
<Form name = "form1">
<Input type = "hidden" name = "hide">
</Form>
The script defines var str = "123 ";
Document. form1.hide. value = str;
Then, just take the value of hidden.
Problem Comment: In the old saying, JSP must be submitted for obtaining JS data, and JS can directly obtain JSP data.