Calling a java method in ajax

后端 未结 2 1899
醉酒成梦
醉酒成梦 2020-12-05 06:00

I am creating a jsp application in Netbeans Ide. I am having problems in calling a java class method in ajax.Is it possible to do so

My java class is something like

2条回答
  •  盖世英雄少女心
    2020-12-05 06:47

    AJAX is an acronym for Asynchronous JavaScript And XML. It provides an ability to communicate with the server asynchronously.

    To explain that in simple terms, you can send a request to server and continue user interaction with the user. You need not wait for response from the server. Once the response arrives, a designated area in UI will update itself and reflect the response information. Whole page need not be reloaded.

    So, you can not access Java Class directly as url to make your Ajax request. It should any mapped url like JSP, Servlets, PHP etc.

    Create a JSP (e.g. hello.jsp)

    <%
    String strResponse;
    mail.Main objMain = new mail.Main();
    strResponse = objMain.execute();
    %>
    
    <%=strResponse %>
    

    In Ajax request

    url: "hello.jsp",
    

    EDIT: Added Example:

     
    
    
                                     
                  
提交回复
热议问题