简体   繁体   中英

Pass value from jsp (java code> to javascript

I have a jsp file called page.jsp, where I have the following code:

<%@page import="soundcap.Soundcap"%> 


<%
Soundcap cfl = new Soundcap();
String sfl = cfl.playFile();
%>

I need the value of sfl in a javascript file jscript.js

Question: How can I pass sfl from jsp and receive this value in javascript?

I have tried <%= sfl %> in javascript but didn't work. I have set session in jsp (session.setAttribute("sfl",sfl) ) and tried to retrieve it in javascript (<%= session('sfl'%>) but it didn't work. Your help please.

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

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