title: How to call function in JSP on button click?
body: <p>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? </p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
              pageEncoding="ISO-8859-1"%&gt;
      &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
      &lt;title&gt;Insert title here&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;%!
      public void display()
      {
          char myArray[][] = new char[10][10];
          System.out.println("&lt;table border=1&gt;");
  
          System.out.println("&lt;tr&gt;"); 
       for(int i=0;i&lt;10;i++)
      {
        for(int j=0;j&lt;10;j++)
        { 
  
            if(i%3==0 &amp;&amp; j%3==0)
            {
               myArray[i][j] = 'x';
               System.out.println("&lt;td align=center&gt;&lt;font color=blue&gt;" + myArray[i][j]+ "&lt;/font&gt;&lt;/td&gt;");
            }
            else
            { 
               myArray[i][j] = 'p';
               System.out.println("&lt;td align=center&gt;&lt;font color=blue&gt;" + myArray[i][j]+ "&lt;/font&gt;&lt;/td&gt;");
       } 
  
      } 
        System.out.println("&lt;/tr&gt;");
  
      }
       System.out.println("&lt;/table&gt;");
      }
  
      %&gt;
      &lt;button onClick="display()"&gt; Display &lt;/button&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>