I'm trying to create an excel file and save to local file system using java applet. After sign the application, i can successfully create the file by directly invoking the applet. However, when i try to call the method from javascript, it failed without any error message. I'm wondering if there is any policy control to prevent java method to be called from javascript? <html><script language="JavaScript">function createExcel(){ document.excel.createExcel(); document.excel.setMessage("hello world from js");}</script><body><input type="button" value="Generate Excel" onclick="createExcel()" /><applet id='applet' name='excel' archive='Office.jar,poi-3.7-20101029.jar' code='com.broadridge.Office.class' width='100' height='100'></applet></body></html> 解决方案 Methods in a trusted applet that are invoked using JavaScript need to be wrapped in a PrivilegedAction and called using one of the AccessController.doPrivileged(..) variants.Sandboxed file-system accessPlug-In 2 JREs (Oracle's 1.6.0_10+ JRE for example) offer sandboxed access to the local file-system using the JNLP API file services (specifically the FileSaveService). See the file service demo. for an example.Applet elementAn applet called by JS should declare that it is scriptable in the HTML. As for getting that 'HTML', the best way to write it is using Oracle's deployJava.js. It will not only write the applet element the best way that is currently known for each browser, but does JRE presence (is Java installed?) and minimum version (is the JRE the minimum version needed to run this applet?) checking. 这篇关于如何从java小程序创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 05:09