<% Soundcap cfl = new Soundcap();...">

Getting jsp value in javascript file

I have the following code in abc.jsp:

<%@page import="soundcap.Soundcap"%> <% Soundcap cfl = new Soundcap(); var sfl = cfl.playFile(); %> 

I need sfl value in external javascript file (jcode.js). How can I get this value (sfl) from jsp in javascript?

+6
source share
3 answers

use this ...

 <% //get your sfl %> <input type="hidden" id="sfl" value="<%=sfl%>"> 

in your js file use

 var sfl=document.getElementById("sfl").value; 
+1
source

Just put your JSP value in the input tag as follows:

 <input type="hidden" id="value" value="${value}"> 

And get this value in JS as follows:

 var value = document.getElementById("value").value; 
+1
source

Very simple:

 <% //get your sfl %> <script> var xyz = <% out.print(sfl); %>; </script> 
0
source

All Articles