This discussion is archived
6 Replies Latest reply: Sep 4, 2013 10:44 PM by Kreetz RSS

How to access a file via Applet and JavaScript

user10047839 Newbie
Currently Being Moderated
I want to copy one file on the client machine from one place to another place from a Java Bean.
To do this I created an applet and a Java Bean as follows:
import java.applet.*;
public class FileUtils extends Applet {
    public void copyFile(String src, String dest)  {
    private String source, destination; // setters/getters are there of course
    public void copyFile(ActionEvent actionEvent) { // Bean
        FacesContext fctx = FacesContext.getCurrentInstance();
        ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
        String command = "var s = '"+ source +"'; var d ='" + destination +"'; " +  " document.fileUtilsApplet.copyFile(s, d); ";
        erks.addScript(fctx, command);
Then I added the APPLET tag referencing the above class in the page fragment:
                    <applet code="FileUtils.class" name="fileUtilsApplet" height="30"
From the Java console I can see the jar is successfully downloaded, but when the code in the bean is executed, the JavaScript code does not seem to do anything, as if the "copyFile" public method was not called at all and no output in the Java Console as well.

Note that I already followed the guidelines at .

Do you have any ideas?


  • Correct Answers - 10 points
  • Helpful Answers - 5 points