java method call from javascript in jsp page

I am new to JSP,
I have method that contains loop and want to display value

<%!
private void getDemo() {
    for(int i=0; i<10; i++) {
        setName("Val: " + i); %>
        <script language="javascript">
            var name = "<%= getName()%>";
            console.log(name);
        </script>
    <%!}
}%>
<%!
String name;
private void setName(String name) {
    this.name = name;
}
private String getName() {
    return this.name;
}
%>

Call

<script type = "text/javascript">
 window.onload=function(){<%getDemo();%>};
</script>

Problem
But when I see the console, It only display Val: 9
How can I achieve all value? I need Script code inside Java Code. Is it Possible?

Answers:

Answer

Your Javascript runs client side in the browser so will not normally interact with your Java code running server side

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.