简体   繁体   中英

Using a Javascript variable in a Jsp scriplet

I want to use a Javascript variable in JSP scriplet of the same page. See example below.

<script language="javascript">
var i=10;
</script >

< % out.println(i); % >

It should print the value of i defined in script tag above. Both script and scriplet are part of the same .jsp page

<div id='out'>
<div>

<script language="javascript">
var i=10;
document.getElementById('out').innerHTML = i ;
</script >

It is not really an answer , because your problem is irrelevant. There is a difference between what gets executed serverside and clientside , and your javascript will get executed clientside , the jsp tags on the server , etc... Either you define and display i in java , or in javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM