是的,你可以通过JS。
阅读http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html
例子:
小程序
public class MathApplet extends Applet{
public void printOut(String text) {
System.out.println(text);
}
}
HTML
<script src=
"https://www.java.com/js/deployJava.js"></script>
<script>
<!-- applet id can be used to get a reference to
the applet object -->
var attributes = { id:'mathApplet',
code:'jstojava.MathApplet', width:1, height:1} ;
var parameters = { jnlp_href: 'math_applet.jnlp'} ;
deployJava.runApplet(attributes, parameters, '1.6');
</script>
JS 调用
mathApplet.printOut("Testing printing to System.out");
编辑:
希望这就是你要找的东西
如果您只想调用一些代码,处理一些不需要用户交互或运行小程序的非绑定功能,那么您可以创建一个导入小程序 jar 的 Java Servlet。然后,您可以引用任何方法并调用它。
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("<YourDomain>/Servlet?param1=value1");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
如果您想从 .cs 调用页面上正在运行的 Java 小程序实例,那么您可以做的是
Response.Write("<script type=\"text/javascript\">myJsAppletCallingMethod();</script>");
或
protected void DoSomethingButton_Click(object sender, EventArgs e) {
ClientScriptManager clientScriptManager = Page.ClientScript;
clientScriptManager.RegisterStartupScript(typeof (Page), "PrintScript_" + UniqueID, "myJsAppletCallingMethod();", true);
}
信用12