【发布时间】:2013-12-15 23:43:37
【问题描述】:
我使用的是jsp格式的eclipse 3.2 tomcat server 5.5。我在将 var 变量(javascript)转换为 int 变量(java)时遇到问题。这样做的正确方法是什么?
在html body中,我用这个方法抛出:
String qwerty = Integer.toString(f);
String asdf = Integer.toString(d);
System.out.println("CONVERTED VALUE : "+qwerty+" "+asdf);
%>
<input type="hidden" id="balance" name="balance" value="<%=qwerty%>" />
<input type="hidden" id="loop" name="loop" value="<%=asdf%>" />
<%
System.out.println("VALUES : "+balance+" "+loop);
在 html 头(脚本)中:
<script>
function myfunction()
{
var looping = document.getElementById("loop").value;
var balancing = document.getElementById("balance").value;
<%
String loop="<%=document.writeln(looping)%>";
String balance="<%=document.writeln(balancing)%>";
int balance = Integer.parseInt(balancing);
int loop = Integer.parseInt(looping);
%>
..........................cont
如何将这个 var 转换为字符串?
【问题讨论】:
-
JSP 页面中的服务器端 Java 代码首先运行并生成扩展模板,然后将其发送到客户端并在那里执行。因此,您似乎无法直接从 JavaScript 调用 Java。您要么需要重新考虑逻辑,要么在新请求中将客户端数据发送到服务器。
-
这个帖子想成为这类问题的规范解释:programmers.stackexchange.com/questions/171203/…。
-
那么我可以在jsp的同一页面中使用request.getParameter吗?
标签: java javascript eclipse jsp tomcat