I wrote a server program in java but in order to give an interface with web i want to access java method in jsp when certain menu button is clicked. How can i do this?
you cannot do this directly because JSP is server side and html is client side. However, it can be accomplished via AJAX. http://en.wikipedia.org/wiki/Ajax_(programming)
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