Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript到jsp_Javascript_Html_Jsp_Variables_Jsp Tags - Fatal编程技术网

javascript到jsp

javascript到jsp,javascript,html,jsp,variables,jsp-tags,Javascript,Html,Jsp,Variables,Jsp Tags,如何在我的jsp中显示javascript“var” ... <script type="text/javascript"> ... // My code to get the value. var val = combo.getValue(); </script> <body> The value is : //to be displayed here </body> 。。。 ... // 我的代码来获取值。 var val

如何在我的jsp中显示javascript“var”

 ...
 <script type="text/javascript">
 ... // My code to get the value. 
 var val = combo.getValue(); 
 </script>
 <body>
 The value is : //to be displayed here
 </body>
。。。
... // 我的代码来获取值。
var val=combo.getValue();
此处显示的值为:/

添加一个HTML元素,该元素应标记要显示值的位置,并为其指定一个
id

<body>
    The value is : <span id="value"></span>
</body>
您只需要确保在加载HTML页面后执行特定脚本。在
窗口中执行此操作。加载
或将
放在
的末尾,或将其包装在对某个事件执行的
函数中

至于JSP部分,这与本文无关。JSP所做的一切就是生成HTML/CSS/JS代码并将其从Web服务器发送到webbrowser。JavaScript对JSP一无所知,它所能看到和访问的只是HTML/CSS,您也可以通过右键单击webbrowser中的页面并选择View Source来看到它

另见:

您需要将其放置在某个位置,以便将其推送到JSP页面。隐藏字段是一个很好的选择:

 <script type="text/javascript">
 ... // My code to get the value. 
 document.getElementById("nn").value = combo.getValue();
 ... you could submit the form here if you want
 </script>
 <body>
 The value is : //to be displayed here
 <form action="yourjsp.jsp" method="get">
     <input type="hidden" id="nn"/>
 </form>
 </body>

... // 我的代码来获取值。
document.getElementById(“nn”).value=combo.getValue();
... 如果你愿意,你可以在这里提交表格
此处显示的值为:/
另一种可能是使用AJAX

无论如何,我建议您多阅读一些关于Web应用程序的一般主题,以区分JSP/JavaScript/POST/GET/CSS/HTML和其他基本概念


祝你好运

这与jsp页面或jsp标记无关
 <script type="text/javascript">
 ... // My code to get the value. 
 document.getElementById("nn").value = combo.getValue();
 ... you could submit the form here if you want
 </script>
 <body>
 The value is : //to be displayed here
 <form action="yourjsp.jsp" method="get">
     <input type="hidden" id="nn"/>
 </form>
 </body>