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?
            Asked
            
        
        
            Active
            
        
            Viewed 3,815 times
        
    2 Answers
5
            
            
        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
 
    
    
        jmj
        
- 237,923
- 42
- 401
- 438
- 
                    probably i made a mistake as it is for server side i shouldn't use jsp. thanks for answering – Taskin Jun 11 '12 at 16:29
- 
                    
- 
                    
1
            
            
        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)
 
    
    
        Jordon Wiarz
        
- 21
- 2
