每当我点击我的网页上的按钮时,我想从jar文件中调用java方法getMessage()。我想知道如何实现这一目标。
我的html文件: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>
我的java文件: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..!!!");
}
}
请有人告诉我如何从Example.jar
调用getMessage()方法