1

In the JSP page below, I am not able to call the function display on button click. How to call this display() service function on button click?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
            pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <%!
    public void display()
    {
        char myArray[][] = new char[10][10];
        System.out.println("<table border=1>");

        System.out.println("<tr>"); 
     for(int i=0;i<10;i++)
    {
      for(int j=0;j<10;j++)
      { 

          if(i%3==0 && j%3==0)
          {
             myArray[i][j] = 'x';
             System.out.println("<td align=center><font color=blue>" + myArray[i][j]+ "</font></td>");
          }
          else
          { 
             myArray[i][j] = 'p';
             System.out.println("<td align=center><font color=blue>" + myArray[i][j]+ "</font></td>");
     } 

    } 
      System.out.println("</tr>");

    }
     System.out.println("</table>");
    }

    %>
    <button onClick="display()"> Display </button>
    </body>
    </html>
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Sanyuja
  • 13
  • 5

2 Answers2

0

You should use JavaScript function instead of Java method. Java code cannot run on client side.

Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49
0

You can't call Java from Javascript code.

But in your case you just adding a table, so you can convert your code to create table dynamically as example

Ori Marko
  • 56,308
  • 23
  • 131
  • 233