Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如:我有 var a=10; 现在我想在jsp标签中使用'a'的值,比如
<% int b= "how to store javascript variable here" %>
您可以在服务器端提交/处理之前在隐藏字段中设置 javascript 变量值,因此它将作为请求参数的一部分发送
document.getElementById('myHidden').value=myVariable;
在服务器端代码中访问 javascript 变量
Request.getParameter("hiddenName")
那是不可能的。您需要阅读客户端和服务器端之间的区别。这是一个非常好的帖子:
https://softwareengineering.stackexchange.com/questions/171203/what-are-the-difference-between-server-side-and-client-side-programming