3

I have a javascript function as below.

<script type="text/javascript">
    window.addEventListener ("message", OnMessage, false);
    function OnMessage (event) {
        var test = event.data;
        <%
             ReadCookiesServlet readCookiesServlet=new ReadCookiesServlet();
             readCookiesServlet.doGet(<%=test%>,response);
       %>
    }
</script>

What I actually needs is to pass the value of event.data to the method doGet.How can I pass this value?

Thanks.

Thilina Sampath
  • 3,615
  • 6
  • 39
  • 65
Hasanthi
  • 1,251
  • 3
  • 14
  • 30

1 Answers1

3

You can use ajax

The problem with you approach is that the java code is compiled before any javascript function is created so it doesnt know what test and will pass <%=test%> as a string to function

Btw readCookiesServlet.doGet(<%=test%>,response); will give you a compile time error because test is not defined in java code it is defined in javascript code and also for its type.

Community
  • 1
  • 1
singhakash
  • 7,891
  • 6
  • 31
  • 65