Add a HTML element which should mark the place where the value is to be displayed and give it an id
.
<body>
The value is : <span id="value"></span>
</body>
Then let your JS access it by document.getElementById()
and modify its inner HTML.
document.getElementById("value").innerHTML = val;
You only need to ensure that the particular script executes after the HTML page has loaded. Do it during window.onload
or put the <script>
at end of <body>
or wrap it in a function
which you execute on some event.
As to the JSP part, this is not relevant here. All JSP does is generating and sending HTML/CSS/JS code from webserver to webbrowser. JavaScript knows nothing about JSP, all it can see and access is HTML/CSS which you can also see by rightclicking the page in webbrowser and choosing View Source.
See also:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…