-3

I want to call a java method getMessage() from a jar file whenever I click button on my webpage. I want to know how to achieve this.

My html file : index.html

   <!doctype html>
   <html>
   <head>
   <meta charset="utf-8"/>
   <script src="jquery-1.11.1.min.js"></script> 
   <script language="javascript">   

      function openMsg()
     {        
        var request = $.ajax({           // Here I am just calling jar file but I want the code to call method getMessage(); 
                   url: "Example.jar",
                   type:"GET",
                   dataType:"html"
                         });     

        request.done(function(msg){
                $("print").html(msg);
                         });

        request.fail(function(jqXHR, textStatus){
                alert("Request failed :",textStatus);
                         });                                    

     }       

   </script> 
   </head>

  <body>
   <button onclick="openMsg();">Click to open message</button>
   <p id="print"></p>
</body>
</html>

My java file : Example.java

    import java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.JApplet;

    public class Example extends JApplet
  {

        public void start() 
      {

      }

        public void init()  
      {
         setBackground(Color.blue);
      }

        public void paint(Graphics g)   
      {
         g.drawString("Hello World !", 100, 100);
      }

         public void getMessage()
      {
          System.out.println("Good Morning..!!!");
      }

  }

Please someone tell me how can I call getMessage() method from Example.jar

9
  • And where would you like that System.out.println to appear? Commented Oct 18, 2016 at 15:26
  • the HTTP GET request arrives at a webserver. That webserver not has to call your java code and that is pretty broad. Also your code extends JApplet, which is something totally unrelated. Commented Oct 18, 2016 at 15:27
  • You need to install some server-side code that responds to HTTP requests by running your Java class. Commented Oct 18, 2016 at 15:27
  • Are you expeciting the Example.java to be on the user's machine? (client-side)? Commented Oct 18, 2016 at 15:29
  • 2
    Please don't repost the same question again. Here is the original question asked some hours ago: stackoverflow.com/questions/40104912/… Commented Oct 18, 2016 at 15:34

1 Answer 1

1

you should create an http servlet to intercept the request (java dows not provide the connectivity). Try to see here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.