I have a scenario where i need to compare javascript varibable with java object inside scriptlet of jsp page. How can i get javascript variable in the jsp scriptlet or the other way will also work for me(getting arraylist object value in javascript).
It is possible, two ways to assign javascript variable value to jsp scriptlet.
First Way Demo1.jsp
<script>
var name = "Gautam";
</script>
<%
String str = "<script>document.writeln(name)</script>";
out.println("value: " + str);
%>
Second Way Demo2.jsp
<html>
<script>
function call()
{
var name = "Gautam";
window.location.replace("Demo2.jsp?name=" + name);
}
</script>
<input type="button" value="Get" onclick='call()'>
<%
String name = request.getParameter("name");
if (name != null)
{
out.println(name);
}
%>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With