title: I want to call a java Method on Button Click In Jsp page
body: <blockquote>
    <p>Here Iam facing a problem If i click a Hyperlink it should run a
    function and be in the same page
            Iam calling a java function update On every click of a particular Link. The update function just Updates the Database Using Jdbc Connection</p>
  </blockquote>
  
  <pre><code>    &lt;div&gt;
          &lt;h2&gt;.  Pick Atleast THREE....And Max TEN&lt;/h2&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;h3 style="text-align: center"&gt;Department : Computer Science&lt;/h3&gt;
          &lt;div class="col three"&gt;             
              &lt;a href="#" class="btn btn-sunflower" onclick="&lt;% update("C++",a, n); %&gt;"&gt;C!&lt;/a&gt;            
          &lt;/div&gt;
  
          &lt;div class="col three"&gt;
              &lt;a href="#" class="btn btn-dark-blue" onclick="&lt;% update("C++",a, n); %&gt;"&gt;C++!&lt;/a&gt;      
          &lt;/div&gt;
  
          &lt;div class="col three"&gt;
              &lt;a href="#" class="btn btn-rouge" onclick="&lt;% update("Java",a, n); %&gt;"&gt;Java!&lt;/a&gt;            
          &lt;/div&gt;
  
          &lt;div class="col three"&gt;
              &lt;a href="#" class="btn btn-dark" onclick="&lt;% update("Java Script",a, n); %&gt;"&gt;Java Script!&lt;/a&gt;       
  
      &lt;/div&gt;
  
      &lt;/div&gt;
  
  
      This is the code for Update function is 
  
  &lt;%! 
                  static char update(String Update,int id,Integer n)
                  {
                      ResultSet rs;
                      System.out.println("The Update Is "+Update+" The id is "+id+"The n values is "+n);
                      Connection con = null;
                      PreparedStatement pst = null;
                      try{
                          Class.forName("org.apache.derby.jdbc.ClientDriver");
                          con = DriverManager.getConnection("jdbc:derby://localhost:1527/Love_To_Learn","Mohammed_Numan","mohammed");
                          String sql = "Update INTREST set Intrest"+n+"='"+Update+"' where USER_ID="+id ;
                          pst = con.prepareStatement(sql);
                          int x = pst.executeUpdate();
                          n++ ;
                      }catch(Exception e){ e.printStackTrace(); }
                  } 
              %&gt;
  </code></pre>
  
  <blockquote>
    <p>This function gets executed those many times this method is Specified
    even without clicking the link.!</p>
  
  <pre><code>Is this way even possible??If not tell me the Possible solution
  </code></pre>
  </blockquote>