Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get javascript variable value in jsp scriptlet [duplicate]

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).

like image 803
participantjava Avatar asked Nov 02 '22 02:11

participantjava


1 Answers

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>
like image 134
Gautam Viradiya Avatar answered Nov 12 '22 12:11

Gautam Viradiya