Access file applet function via javascript

hi all
when i want to have access to the method (which in fact read a file) of my applet class via javascript, a java error is raised: access denied
BUT i have signed the related jar!
when i want to access the method (which in fact read a file) of my applet class via the normal way (put a button into a frame and....) it works.
are there more configurations to do or ....?
Kind Regard Tom
here is the code
HTML file
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
     <head>
     <link type="text/css" rel="stylesheet" href="/css/style.css">
          <script type="text/javascript">
          function xclick() {
          alert( document.getElementById('applet').isFileOk());
          document.getElementById('fichier').value = document.getElementById('applet').isFileOk();
          //alert(document.portal.applet.isFileOk(path));
          function checkfile() {
               //var fichiercacher = document.portal.fichier.value;
               var fichiercacher = document.getElementById("fichier").value;
               document.getElementById("fichiercacher").value = fichiercacher;
               document.getElementById("fichiercacher").value = fichiercacher;
               document.getElementById("chemin").value = fichiercacher;
               alert("fichier cacher" + fichiercacher);
               alert("chemin=" + document.getElementById("chemin").value);
          </script>
     </head>
     <body >
     <form name="portal" method="post" action="" >
<p align="center" id="corps">
     <img border="0" src="ilias.bmp"><br>
     <applet id="applet2" code="NumberOfLine.class" archive="NumberOfLine.jar" width="150" height="109" >
          <param name="maxLines" value="50" />
          <param id="chemin" name="fichierparam" value="" />
          </applet>
          <applet id="applet" code="localfile.class" archive="localfile.jar" width="150" height="109" >
          <param name="maxLines" value="50" />
          <param id="chemin" name="fichierparam" value="" />
          </applet>
     <br>
               <div id="divloading" ></div>
     <input type="hidden" name="fichiercacher" />
     <input type="file" name="fichier" onchange="checkfile()">
<input type="button" value="click me" onClick=xclick() ; />
     </p>
     </form>
     </body>
     </html>
Class NumberOfLine javascript way
import java.applet.Applet;
import java.awt.Button;
import java.awt.Label;
import java.io.*;
public class NumberOfLine extends Applet {
private boolean fileok = false;
Label message = new Label("MAX line = 40 ");
Button btnok = new Button("check file");
int maxline = 40;
public void init() {
     String sMaxLines = getParameter("maxLines");
     if ( sMaxLines != null ){
               this.maxline = Integer.parseInt(sMaxLines);
               System.out.println(this.maxline);
     public String isFileOk(String chemin) {
          File ffile = new File( chemin);
          try{
               FileReader fr = new FileReader(ffile);
               LineNumberReader ln = new LineNumberReader(fr);
          int count = 0;
          while (ln.readLine() != null) {
          count++;
          System.out.println("Total line no: " + count);
               ln.close();
               fileok = (count <= maxline);
          catch(IOException e){
               e.printStackTrace();
               System.out.println(e.toString());
          return fileok ? "ok" : "nok";
CLass localfile Normal way
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.lang.*;
import java.text.*;
import java.awt.event.*;
import java.io.*;
public class localfile extends Applet {
     public localfile() {
          Panel p = new Panel();
          Font f;
          String osname = System.getProperty("os.name","");
          if (!osname.startsWith("Windows")) {
               f = new Font("Arial",Font.BOLD,10);
          } else {
               f = new Font("Verdana",Font.BOLD,12);
          p.setFont(f);
          p.add(new Button("Open"));
          p.add(new Button("other"));
          p.setBackground(new Color(255, 255, 255));
     p.setSize(800, 800);
          add(p);
          setSize(800, 800);
          setVisible(true);
     public String isFileOk(){
               System.out.println("OPEN CLICKED");
               int arrlen = 10000;
               byte[] infile = new byte[arrlen];
               Frame parent = new Frame();
               FileDialog fd = new FileDialog(parent, "Please choose a file:",
               FileDialog.LOAD);
               fd.show();
               String selectedItem = fd.getFile();
               if (selectedItem == null) {
                    // no file selected
               } else {
                    if ((fd.getFile()).endsWith("txt") || (fd.getFile()).endsWith("text")){
                         File ffile = new File( fd.getDirectory() + File.separator +
                         fd.getFile());
                         // read the file
                         System.out.println("reading file " + fd.getDirectory() +
                         File.separator + fd.getFile() );
                         try {
                              FileInputStream fis = new FileInputStream(ffile);
                              BufferedInputStream bis = new BufferedInputStream(fis);
                              DataInputStream dis = new DataInputStream(bis);
                              try {
                                   int filelength = dis.read(infile);
                                   String filestring = new String(infile, 0,
                                   filelength);
                                   System.out.println("FILE LENGTH=" + filelength);
                                   System.out.println("FILE CONTENT=" + filestring);
                              } catch(IOException iox) {
                                   System.out.println("File read error...");
                                   iox.printStackTrace();
                         } catch (FileNotFoundException fnf) {
                              System.out.println("File not found...");
                              fnf.printStackTrace();
                    } else {System.out.println("Error this is not a txt file"); }
          return "turc";
     public boolean action(Event evt, Object arg) {
          if (arg.equals("Open")) {
               System.out.println("OPEN CLICKED");
               int arrlen = 10000;
               byte[] infile = new byte[arrlen];
               Frame parent = new Frame();
               FileDialog fd = new FileDialog(parent, "Please choose a file:",
               FileDialog.LOAD);
               fd.show();
               String selectedItem = fd.getFile();
               if (selectedItem == null) {
                    // no file selected
               } else {
                    if ((fd.getFile()).endsWith("txt") || (fd.getFile()).endsWith("text")){
                         File ffile = new File( fd.getDirectory() + File.separator +
                         fd.getFile());
                         // read the file
                         System.out.println("reading file " + fd.getDirectory() +
                         File.separator + fd.getFile() );
                         try {
                              FileInputStream fis = new FileInputStream(ffile);
                              BufferedInputStream bis = new BufferedInputStream(fis);
                              DataInputStream dis = new DataInputStream(bis);
                              try {
                                   int filelength = dis.read(infile);
                                   String filestring = new String(infile, 0,
                                   filelength);
                                   System.out.println("FILE LENGTH=" + filelength);
                                   System.out.println("FILE CONTENT=" + filestring);
                              } catch(IOException iox) {
                                   System.out.println("File read error...");
                                   iox.printStackTrace();
                         } catch (FileNotFoundException fnf) {
                              System.out.println("File not found...");
                              fnf.printStackTrace();
                    } else {System.out.println("Error this is not a txt file"); }
          } else return false;
          return true;
}

Thx you were a great due to my big lak of java skills.
i found the solutions and for those who are interrested here is the code:
public String isFileOk(final String filepath){
          System.out.println("OPEN file=" + filepath);
          int arrlen = 10000;
          byte[] infile = new byte[arrlen];
                    try {
               FileInputStream fis = (FileInputStream) AccessController.doPrivileged(
               new PrivilegedExceptionAction() {
               public Object run() throws FileNotFoundException {
               return new FileInputStream(filepath);
                         BufferedInputStream bis = new BufferedInputStream(fis);
                         DataInputStream dis = new DataInputStream(bis);
                         try {
                              int filelength = dis.read(infile);
                              String filestring = new String(infile, 0,
                              filelength);
                              System.out.println("FILE LENGTH=" + filelength);
                              System.out.println("FILE CONTENT=" + filestring);
                         } catch(IOException iox) {
                              System.out.println("File read error...");
                              iox.printStackTrace();
                         } finally {
                              try {
                                   fis.close();
                              } catch(IOException ioe) {
                                   //oops
               } catch (PrivilegedActionException e) {
               // e.getException() should be an instance of FileNotFoundException,
               // as only "checked" exceptions will be "wrapped" in a
               // PrivilegedActionException.
               //throw (FileNotFoundException) e.getException();
                    e.printStackTrace();
                    return "nok";
               return "ok";
     }

Similar Messages

  • Firefox 4.0 support for printing embedded PDF files in iFrames via JavaScript

    I recently upgraded to Firefox 4.0 and can no longer print embedded PDF documents contained in an iFrame.
    My company's web application has several pages which load PDF files from a Servlet into an iFrame. The pages in question all have "Print" buttons which when clicked executes a JavaScript function to obtain reference to the iframe containing the PDF, place it into focus() (e.g., frames['pdfdoc'].focus();), and invoke print() (e.g., frames['pdfdoc'].print();). There are no errors, or exceptions caught when the JavaScript function is invoked, but the "Print" button is no longer operational.
    Does Firefox 4.0 no longer support iFrames? The issue goes away if I revert back to ver 3.6.16

    I have same issue for printing embedded PDF files in iFrames via JavaScript in Firefox 5.0.
    In previous versions it was working fine. But not in Firefox 4.0/5.0.
    Is there any solution for this problem?

  • Accessing a network resource via javascript

    Hello,
    we have been using Adobe Reader for linux provided by the yum repository for quite some time, without major issues. Currently, however, we are seeing a mysterious problem with a PDF form which is designed to exchange data with a local server, using javascript functionality, as far as I can see. On one of our machines (running CentOS 5.8 64-bit) this has stopped working recently, and I cannot figure out why. Clicking the respective field simply has no effect, there is no error message, neither in the Reader window, or on the console, both in normal mode and debug mode. Nothing in the system logs either. The function simply seems to be ignored!
    Some observations which might be helpful:
    1. Uninstalling and reinstalling the Reader package, after clearing all personal preferences, did not have any effect.
    2. Using a fresh version of the PDF form did not solve the problem.
    3. Firewall and SElinux are disabled anyway.
    4. With a "clean" account on the same machine, the same problem occurs.
    5. On a very similar machine (same OS, same Reader version) the operation is working properly!
    So it seems to be something specific to this machine, but not specific to a certain account. It is obviously neither a corrupted Reader installation, nor a problem with this specific reader version, nor a corrupted PDF form. Now I am running out of ideas...
    Any suggestions what else might be preventing network access (via javascript) from functioning properly? Javascript itself is (by default) enabled in the preferences.
    Thanks in advance
    Oliver

    Sorry for the double post, but help would be appreciated...

  • Uploading a File with AppleScript via JavaScript

    Hi everybody,
    being new to AppleScripting and JavaScripting I'm faced with the following problem:
    Is it possible to make AppleScript to input the path for a file to be uploaded via JavaScript? If yes, what should be the correct Path Format and how to wrap it up the JavaScript action into AppleScript? I've tried a few comands but to no success.
    On the webpage in question, there's a "Choose" button, that is defined as follows:
    <input type=​"file" class=​"gwt-FileUpload" name=​"swfFile">​
    I've been trying to use the following syntax:
    do JavaScript "document.getElementsByName('swfFile')[0].value('Macintosh HD:Users:myaccount:Desktop:Scrapbook:!动画.swf')" in document 1
    as well as this one, where the Path is definitelly understood by shellscript:
    do JavaScript "document.getElementsByName('swfFile')[0].value('/Users/myaccount/Desktop/Scrap book/!动画.swf')" in document 1
    The name of the file is (and must remain) in chinese, but for testing purposes I have also tried files with english names, without success.
    Currently I'm using a solution with JavaScript comand:
    do JavaScript "document.getElementsByName('swfFile')[0].click()" in document 1
    to click the finder  window to browse for the file, and manipulating  keystrokes by using System Events to find the right file, but it's not  infallible with a number of files and it's hardly an ellegant sollution.
    Any idea what I'm doing wrong?
    Cheers!

    @twtwtw
    the do JavaScript "document.forms[0].submit()" command didn't work, so I kept the original way of submitting by clicking the button. The submitting part works, but not the input file part.
    That's the code I used
        tell application "Safari"
            do JavaScript "document.getElementById('gwt-uid-13').value='on'" in document 1
            do JavaScript "document.forms[0].elements['swfFile'].value=" & "'" & SWFFilePath & "'" in document 1
            do JavaScript "document.getElementsByClassName('gwt-SubmitButton')[0].click()" in document 1  
            delay 1
        end tell
    with SWFFilePath set as the POSIX path as well as the default file format
    Macintosh HD:Users:myaccount:Desktop:Scrapbook:!动画.swf'
    but it did not work.
    If you've got the time, feel free to upload an .swf. The service is free and the server delats uploaded files after 15 min. (if you don't have any, you may try an empty .txt file instead - it won't get converted, but the point is just to get it into the input box).
    In the meantime, I'll have a look at adayzdone's suggestion. It's not perfect (the downside being that it requires the window to be active, so I can't run the script in the background or with my screensaver & password on), but it's still more reliable than my sollution with navigating arrowkeyes.

  • Best way to access files on Xserve via VPN on iPad?

    Can anyone tell be the best solution for accessing files housed on the companies Apple Xserve remotely via VPN from an iPad? Numbers / Pages etc.
    thanks,
    Rick

    The iPad doesn't natively support file systems such as those on servers, but there are third-party apps that can allow this. FileBrowser is one often mentioned, so you might look into that. VPN will be a separate issue; iOS has a built-in VPN client which works with many VPN systems, but you'll need to see if yours is supported.
    Regards.

  • Accessing built in functions through javascript

    Hi everyone,
    Is there a way to call one of the built-in functions using javascript? For example, I added a click_box, and the on-success events I can choose to continue, go to a different slide, open a file/url etc. I can also choose to execute a javascript.
    My question is, can I choose to execute a javascript, and then within that javascript, call the "open a file/url" and pass it a variable (url)?
    The reason I want to do this is when a user clicks on a link to open a URL, I want the movie to pause until they return and click on the next button to proceed.
    Unless of course there is a much easier way to accomplish this.
    Thanks,
    Manny

    Hello again
    With JavaScript option you generally create your own functions. And really, IMNSHO that's what the purpose of the JavaScript option is really for. Perhaps you want to open a link in a specifically sized and placed window with specific attributes such as no Toolbar, no Status bar or Menu bar. In this case you would create a function to do this, then call the function from JavaScript.
    Then again, JavaScript is a whole other wiggly nest of wiener dogs! My simpleton opinion is to do as much as you possibly can in Captivate without resorting to Flash or JavaScript or any other "layer". Because when things go wrong (and trust me, they ALWAYS do) there is less to confuse issues.
    Cheers... Rick
    Helpful and Handy Links
    Begin learning Captivate 5 moments from now! $29.95
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcererStone Blog
    Captivate eBooks

  • Accessing Signed Applet Method From Javascript

    Hi All,
    In my intranet application i have to retrive the mac addres of the client using the applet. I have to capture the MAC Address and set it as a hidden value in the jsp page.
    I have used the signed applet and able to retrive the mac address of the client using IE but I am not able to do the same on NN 7.1
    Below is my javascript and the applet tag syntax, please help me if i am wrong anywhere
    function mac()
    var mval=document.myApplet.getWinMACAddress()
    alert("addres" +mval)                         
    document.loginform.js_value.value=mval
    and the applet tag in my jsp page is
    <applet code ="SignedAppletDemo.class" codebase="http://mysouthasia/AcadResource/jsp/" archive="SSignedApplet.jar" width=1 height=1 align=center name="myApplet" >
    </applet>
    Thanks in Advance

    Since getWinMACAddress( ) seems to work just fine for IE, is there an equivalent for NN7.1?
    What happens if I run Opera instead, and on a Linux system? Or Safari on OS X? Obviously getWinMACAddress( ) isn't going to work for that.
    I really don't understand why so many Asian programmers get "Find the MAC address of..." as a homework assignment. There are many reasons why it isn't really practical to do so, and for examples, just search this forum for MAC addresses. Lots and lots of examples and counter examples.

  • Access files on mac via internet from winXP

    I set up a mac in the office as a file server. I have the public folder defined to be accessible via afp and smb.
    When I access it from home with my mac via "connect to server" and put in the servername.com which I defined with no-ip.com it works just fine. Also my filemaker databases and everything.
    However if I try to connect with a windowsxp machine I cannot get it to work. I tried
    afp://servername.com and smb://servername.com and smb\\servername.com to no avail.
    Any suggestions how this should work?
    Yours
    Pierre

    than you. I wasn't sure what forum to post in. Since I am looking for a remote solution, and possibly apple remote desktop that offers hard drive access only, I thought this could be the appropiate forum. I wasn't sure if remote desktop (apple) offers access to the hard drive to hard drive solution without being forced or required to use the screen sharing/control feature. At any rate, thank you. i am not sure I am going to be able to fins asolution. I was thinking someone might tell me something about SSH, and maybe a third party app to use for dynamic DNS and an option to avoid port forwarding etc. Thank you for your time.

  • Accessing APP_USER and APP_SESSION via javascript

    G'day All,
    I've tried a couple of ways based on results from google this forum to access APP_USER and APP_SESSION with in javascript.
    The answer must not be to just pass it in as a parameter as I'm overriding "showHide" function for the the "Show Hide region" to record if the region was shown or not so that when the page is refreshed the regions will open automatically.
    I've tried to just simply try for example: alert('app_user: #APP_USER# app_session: #APP_SESSION#') but it does not work they way I ant it :(
    Can any one help please.
    Regards
    Mark

    Hello,
    You should take a look at this
    http://www.oracle.com/technology/products/database/application_express/packaged_apps/packaged_apps.html#STICKY
    It is example code of doing exactly that. At the moment it is per session but it should be pretty easy to extend to save that into a user table. You won't need to access those variables on the client side but can do it in the OnDemand Process.
    Carl

  • How to access files on server via VPN

    hey,
    i have set up all the VPN side of the server and is all working.
    Opened all ports for vpn services on my router etc.
    At work we have a situation that automatically logs into the server and opens files. This also puts the server under "shared" in the finder window.
    The question is how do i replicate seeing the files or the server under the shared area in finder as if we were at work?
    I have read other peoples posts and the only things i can see is about wide area bonjour. Is this what i need to setup?
    all help appreciated.

    solved elsewhere

  • Problem with access JSF applet using javascript

    Can someone help me!
    I'm using a applet in jsf page, and i'm trying to access this applet using a javascript.
    Here is the applet code
    <jsp:plugin code="DoAction.class" codebase="." height="400" hspace="10" jreversion="1.5" type="applet" vspace="50" width="100" name="myApp"/>
    Here is the javascript
    function printReturn()
    var a = document.myApp.returnString();
    alert(a);
    "returnString" is the method in applet which simply return a string
    But it doesn't work, it works well when i'm using this applet in JSF
    <applet code="DoAction.class" width="100" height="50" name="myApp" ></applet>
    Unfortunately it's depricated!
    Please tell me what is the solution....

    Thank You for replying.
    I'm trying to call applet method using JavaScript.
    It works when i'm using below apllet tag.
    <applet code="DoAction.class" width="100" height="50" name="myApp" ></applet>
    But it's deprecated
    It doesn't work for below applet tag
    <jsp:plugin code="DoAction.class" codebase="." height="400" hspace="10" jreversion="1.5" type="applet" vspace="50" width="100" name="myApp"/>
    This is my javascript
    <script type="text/javascript">
    function setSearch()
    var a = document.myApp.returnString();
    alert(a);
    </script>

  • Applet function call from javascript

    Hi,
    I'm haveing a problem with accesing applet's functions from Javascript in Mozilla. IE works fine but in Mozilla I get the following error:
    Error: document.applets[0] has no properties
    The code used is: document.applets[0].test();
    The applet has the following 2 tags defined, I don't know if they are necessary here but I'm doing the reverse too (applet functions call javascript).
    <PARAM name="MAYSCRIPT" value="Y">
    <PARAM name="SCRIPTABLE" value="Y">
    If you have any ideea please help.
    Thanks

    in javascript try document.getElementById("idOfTheApplet")
    use object tag instead of applet tag:
         <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
                  height="300" width="450" >
            <param name="code" value="appTest.class" />
            <!--[if !IE]> Mozilla/Netscape and its brethren -->
            <object classid="java:appTest.class"
                    height="300" width="450"
                    >
              <param name="mayscript" value=Y" />
            </object>
            <!-- <![endif]-->
          </object>or check out HtmlConverter.exe in the jdk bin dir.

  • How jsp can call applet functions

    good morning to all java experts
    i have one problem that is
    in my application i have one applet in the server side which contains functions like encryption, decryption, hash functions.
    whenever any client wants to store some information on server side then he download the applet from the server and he gives his own key and encrypt all the contents and these encrypted message only transmitted through media and store on server side
    whenever clients wants to retrieve some information from server then he fetch the only encrypted message to client side then he down load the applet from server and decrypts the message as he pass the previous key.
    the problem is that whenever jsp calls the applet functions through javascript it displaying error message like: error in the jsp page
    but this concept working through html page properly
    plss reply as soon as possible
    thanking uuu

    the problem is that whenever jsp calls the applet functions through javascript Show the relevant code how you thought to accomplish this (this is namely impossible without firing a new request to the server).
    it displaying error message like: error in the jsp pageAnd further on, you -as developer- should know that it is not-done and unclear to talk about errors if they are irrelevant. Always post and the full, complete, original and unchanged error message and -if in Java- also the stacktrace. They are helpful in debugging.

  • How to get list of selected files from swf to javascript ?

    Hi everybody,
    i want to make an upload script with swf and javascript. I want to do selecting files via swf then uploading files to server via javascript. I have searched SWFupload plugins but they are not working as i need. I am new here and i do some search, i see it is possible to save list of selected files in FileReferenceList array, but i dont know if is it possible to pass this array into javascript and then make upload progress via javascript ?

    Hi,
    You will not be able to get the local file paths from FileReference due to flash security restrictions.
    Hence I think it is not possible to pass the file reference data to javascript and load the same.
    Warm Regards
    Deepanjan Das
    http://deepanjandas.wordpress.com/

  • Problem with accessing Signed Applet from javascript method

    Hi,
    I am facing the following problem while accessing Signed Applet from javascript method.
    java.security.AccessControlException: access denied (java.io.FilePermission c:/temp.txt read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at FileTest.testPerm(FileTest.java:19)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at sun.plugin.javascript.invoke.JSInvoke.invoke(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
         at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
         at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
         at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
    I am using jdk1.5 for my development...
    Can anyone help to resolve this security issue. Urgent...
    Thanks in advance.

    Hey thanks. I wasn't able to get it to work with that sample but I did find this very similar code that does allow javascript to call JFileChooser in an applets public method.
    java.security.AccessController.doPrivileged(
    new java.security.PrivilegedAction()
    public Object run(){                           
    //do your special code here
    return null; //return whatever you want
    It seems a bit tempermental in that if you don't select a file quickly, it will hang the browser....no perfect solution but I'm going in the right direction.
    Thanks,
    Scott

Maybe you are looking for