当前位置:编程学习 > JAVA >>

js调用applet方法,删除本地图片

当我用js调用applet的删除本地图片的方法就会报java.security.AccessControlException安全问题
而我用applet调用删除本地图片方法就不会报
注:applet我已经加了数字签名。。

高手们,有没有遇到这种问题 --------------------编程问答-------------------- 本来的方法是:
  public void delete()
       {
                        File file = new File("c:/5.jpg");
                   file.delete();

         
       }

改成:
public void delete()
       {
        SwingUtilities.invokeLater(new Runnable() {   
               public void run() {   
                File file = new File("c:/5.jpg");
                   file.delete();
               }   
           });  
         
       }

--------------------编程问答-------------------- 以上方法就可以解决 --------------------编程问答-------------------- JS是不能操作本地文件的。
applet可以 --------------------编程问答-------------------- js可以通过new ActiveXObject("Scripting.FileSystemObject")来操作本地文件如删除操作 --------------------编程问答-------------------- ? --------------------编程问答-------------------- java 代码? --------------------编程问答-------------------- http://hi.baidu.com/liu_yin/blog/item/1b8180355d33f186a71e12f2.html --------------------编程问答-------------------- --------------------编程问答-------------------- 我也遇到了这个问题,签了名的applet绕过js时在applet里面设置按钮可以通过监听进行操作,为了灵活性,我是想通过html设置按钮,通过js调用applet的方法读取本地文件进行加解密等操作,虽然applet签了名,但是通过js调用时就会报出null input buffer错误,是不是js缓冲存储的问题,一个多星期了,还没解决这个问题,快崩溃了,大家有想发的赶紧讨论讨论啊,楼主有好的解决方案共享一下,在此表示感谢! --------------------编程问答-------------------- 我也遇到了这个问题,签了名的applet绕过js时在applet里面设置按钮可以通过监听进行操作,为了灵活性,我是想通过html设置按钮,通过js调用applet的方法读取本地文件进行加解密等操作,虽然applet签了名,但是通过js调用时就会报出null input buffer错误,是不是js缓冲存储的问题,一个多星期了,还没解决这个问题,快崩溃了,大家有想发的赶紧讨论讨论啊,楼主有好的解决方案共享一下,在此表示感谢! --------------------编程问答-------------------- 还有,可以通过js调用applet实现文件上传(到服务器),socket连接,但是把这个方法迁移到applet里面就出问题了,理论上讲不应该出现问题 的 
package applet;

import java.applet.Applet;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

//本地文件上传(与servlet交互)
public class AppInt extends Applet {

private static final long serialVersionUID = 1L;

//private String filePath="c:/test.txt";
//private String fileName="test.txt";
//private String url="http://localhost:8080/appUpFile/servlet/Receive";


//private String filePath="C:/Documents and Settings/Administrator/Workspaces/MyEclipse 8.5/appUpFile/WebRoot/1.jpg";
//private String fileName="1.jpg";
//private String url="http://192.168.0.53:8080/appUpFile/servlet/Receive";//服务器端servlet路径


private String filePath;
private String fileName;
private String url="http://192.168.0.53:8080/appUpFile/servlet/Receive";//服务器端servlet路径

private boolean bl=false;
public String getFilePath() {
   return filePath;
}

public void setFilePath(String filePath) {

   this.filePath = filePath.replaceAll("/", "\\");
   System.out.println("filePath:"+this.filePath);
}

public String getFileName() {
   return fileName;
}

public void setFileName(String fileName) {
   this.fileName = fileName;
   System.out.println(this.fileName);
}

public String getUrl() {
   return url;
}

public void setUrl(String url) {
   this.url = url;
   System.out.println(this.url);
}

public void setBl(){
   this.bl=true;
   System.out.println(this.bl);
   send();
}

public void init() {   
   //if(this.bl){ 
    send();
    
  // }
}

public void send() {
   {
   
    try {
     String filePath=getFilePath();
     String fileName =getFileName();    
     String urlstring=getUrl();

     System.out.println(filePath+"*****");
    //网络路径很重要
    URL url1 = new URL(urlstring+"?fileName="+URLEncoder.encode(fileName,"utf-8")) ;
    System.out.println(url1+"*****");
    //打开socket连接
    
     HttpURLConnection conn = (HttpURLConnection) url1
     .openConnection();
    
   conn.setRequestMethod("POST"); 
   conn.setAllowUserInteraction(true);
   conn.setDoInput(true);
   conn.setDoOutput(true);
   conn.setUseCaches(true);
   conn.setRequestProperty("Content-Type", "application/octet-stream");

  
   File pfxFile = new File(filePath);
   if (pfxFile.isFile()) {
    // 简历文件的输入流
    FileInputStream fileInputStream = null;
    fileInputStream = new FileInputStream(pfxFile);
    BufferedInputStream bis = new BufferedInputStream(
      fileInputStream);
    OutputStream os = conn.getOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(os);
    int len = 0;
    byte[] bty = new byte[4096];
    while ((len = bis.read(bty, 0, 4096)) != -1) {
     bos.write(bty, 0, len);
     bos.flush();

    }
    bos.close();
    bis.close();
    System.out.println(conn.getContentType() + ": "+ conn.getResponseCode());
   }
    } catch (Exception e) {
     e.printStackTrace();

    }

   }
}
}
 

补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,