0

Good Morning:

I am having several problems trying to receive a String from Java to JSP (Javascript inside).

Java File

String var = "Hello World!";

JavaScript (inside the JSP):

window.onload = function() { 

    loadData();
};    


function loadData() {

    document.getElementById('paragraph').innerHTML = "<%=var%>";

    alert(matr1); } 
}

But I received org.apache.jasper.JasperException: Cannot compile the class.

The rest of JSP and JavaScript is correct, I am trying only to fill the select with the text received in Java, I read other topics but nothing works.

Any help?

Thanks.

Super Hans
  • 128
  • 2
  • 11
DeathGun
  • 79
  • 2
  • 10

1 Answers1

0

The <%= %> or the expression tag is used in jsp as a replacement for out.print() function of java.
You don't need to put double quotes around it to use it in java script, in your case if you have imported the java file into your jsp correctly then i think this should work:

document.getElementById('paragraph').innerHTML = <%=var%>;

Or

try using the variable name directly,

document.getElementById('paragraph').innerHTML = var;
ItamarG3
  • 4,092
  • 6
  • 31
  • 44