我想调用按钮上的java方法Click In Jsp页面

时间:2017-11-17 14:20:13

标签: html jsp

  

这里我遇到问题如果我点击一个超级链接它应该运行一个   功能并在同一页面           Iam调用java函数更新每次单击特定链接。更新功能只是使用Jdbc连接更新数据库

    <div>
        <h2>.  Pick Atleast THREE....And Max TEN</h2>
    </div>

    <div class="row">
        <h3 style="text-align: center">Department : Computer Science</h3>
        <div class="col three">             
            <a href="#" class="btn btn-sunflower" onclick="<% update("C++",a, n); %>">C!</a>            
        </div>

        <div class="col three">
            <a href="#" class="btn btn-dark-blue" onclick="<% update("C++",a, n); %>">C++!</a>      
        </div>

        <div class="col three">
            <a href="#" class="btn btn-rouge" onclick="<% update("Java",a, n); %>">Java!</a>            
        </div>

        <div class="col three">
            <a href="#" class="btn btn-dark" onclick="<% update("Java Script",a, n); %>">Java Script!</a>       

    </div>

    </div>


    This is the code for Update function is 

<%! 
                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(); }
                } 
            %>
  

此方法被指定多次执行此方法   即使没有点击链接。!

Is this way even possible??If not tell me the Possible solution

0 个答案:

没有答案