js 调用applet 访问本的文件

来源:互联网 发布:java web接口开发demo 编辑:程序博客网 时间:2024/05/17 03:57

http://weibaojun.iteye.com/blog/471665


在js中调用Applet中的方法,当Applet中的方法需要访问本地文件系统时,即使你的Applet 是经过签名的,也会报异常,不能正确地访问本地文件系统,解决的办法是:
将原来Applet中的方法:


/** * 提供页面中用js调用导出Excel的方法 */public void exportExcel() {if (showPanel instanceof IstatReportPanel) {((IstatReportPanel) showPanel).exportExcel();}}

修改为:

/** * 提供页面中用js调用导出Excel的方法 */public void exportExcel() {if (showPanel instanceof IstatReportPanel) {SwingUtilities.invokeLater(new Runnable() {public void run() {((IstatReportPanel) showPanel).exportExcel();}});}}

就可以了。在js中调用:

<%-- * @file:bb_query.jsp * @author:Wei Baojun * @date?2009.6.11 * @reviser:Wei Baojun * @reviseDate: 2009.6.11 * @description: 报表填报显示Applet * @version:1.0 --%><%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" %><%@ include file="/include/header.jsp"%><style><!--body{  margin: 0px;  padding: 0px;}--></style><script language="javascript"><!--document.body.onload = function (){document.body.scroll = "no";}--></script><%String url = request.getRequestURL().toString();String servletPath = request.getServletPath();url = url.replace(servletPath,"");request.setAttribute("basePath",url);String sessionId = session.getId();request.setAttribute("sessionId",sessionId);%><OBJECT id="appletObj" name="appletObj" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="100%" height="100%" codebase="/istat3/bbgl/bbtbcl/jvm/jre-1_5_0-windows-i586.exe#Version=1,5,0,0">  <param name="baseUrl" value="${basePath}" />  <param name="instBbId" value="${param.instBbId}" />   <param name="bbDesignerBm" value="${param.bbDesignerBm}" />   <!--<param name="instBbId" value="8aceec0c22cf745e0122cf7a25920001" />-->  <param name="sessionId" value="${sessionId}" />  <param name="code" value="com.longtop.istat3.bbgl.applet.dtable.QueryBbApplet">  <param name="codebase" value="${CONTEXT_ROOT}/bbgl/bbtbcl/lib">  <param name="version" value="2009091807" />  <param name="archive" value="2009091807.jar,IKExpression2.0.jar,jxl.jar,commons-collections.jar,swingx-0.9.2.jar,commons-lang.jar,spring-2.5.6.jar,commons-logging.jar">  <param name="cache_option" value="NO"></OBJECT><script language="javascript"><!--/**     * 打印报表的方法 */function printTable(){var appletObj = document.getElementById("appletObj");appletObj.printTable();}/**     * 导出报表的方法 */function exportExcel(){var appletObj = document.getElementById("appletObj");appletObj.exportExcel();}--></script><%@ include file="/include/footer.jsp"%>