calling java method in javascript [closed]

As javascript is a client side script, it cannot invoke java methods directly which resides on the server

Without any particular java frameworks, you could make use of Java Server Pages (JSP) to invoke deleteconfig.initiate() when it receives a GET request from javascript.

Sending Request

You might also want to use JQuery (a javscript plugin – http://jquery.com/) to send an asynchronous GET request to the server like this

//javascript code
function callInititiate(){

   //This sends a get request to executeInit.jsp
   //
   $.get('localhost/myWebbApp/executeInit.jsp');

}

$(callInitiate);

Receive Request

On the server side, you should have executeInit.jsp that calls deleteconfig.initiate() static method

//in executeInit.jsp
<%@ page import="deleteconfig"%>

<%
// executes initiate() static method
deleteconfig.initiate();

%>

Perhaps reading more about Java Server Pages can get you started!

Leave a Comment