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,8017 gold badges43 silver badges67 bronze badges
asked Mar 29, 2015 at 15:01
Hasanthi
1,2913 gold badges15 silver badges31 bronze badges
1 Answer 1
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.
answered Mar 29, 2015 at 15:09
singhakash
7,9196 gold badges33 silver badges65 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
singhakash
@Hasanthi if you find my answer helful consider accepting it
Hasanthi
Can You please help me to write an ajax call for this
singhakash
@Hasanthi yes ufcorse check the link in my answer if you find any trouble then let me know.
default
readCookiesServlet.doGet(<%=test%>,response);wtf dude? you shouldn't calldoPostanddoGetservlet methods yourself.$.getwill do the work.