Using ajax (using jQuery.ajax
, you could make a request to server, In your case may be to a Servlet
which will invoke method on server that you requested
For example:
function callMe(){
$.ajax({
type: "POST",
url: "/someServlet",
data: { methodToInvoke: "sayHello" , data: "Abc" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
}
at Servlet
end
doPost(...){
String methodToCall = request.getParameter("methodToCall");
//do some stuff to determine method to call and call it like
methodService.invoke(request.getParameter("data"));
}
Also See
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…