Access variable speed with javascript

<head> #set($test = "works")) </head>

<script> 
    var get = "${test}"; // I also tried using '$test' and "$test" also

    alert(get);
</script> 

And it notifies $ {test} , but should print working .

How can I make it work?

+5
source share
5 answers

try it...

    #set ($test = "works")

  <script type="text/javascript">
       var myvar = "${test}";
       alert (myvar);
  </script>

THIS WORKS FREE !!!

+5
source

Try var get = "$test";insteadvar get = "${test}";

+2
source

, , :

#set ($test = "hi")
<script>
    alert("$test");
</script>

, .

+1

, - jstl c: out, :

var get = "<c:out value='${test}' />";

which should work and don't forget to add jstl include at the top of the page

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
0
source

Just use it as in html:

<script> 
    var get = $test;

    alert(get);
</script> 
0
source

All Articles