Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28
  1. #21
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    grant {
    permission java.security.AllPermission;
    permission java.io.FilePermission "<<ALL FILES>>", "write, read";
    permission java.io.FilePermission "C:\\Users\\Jet\\workspace\\Trying\\bin\\*", "read, write";
    };

    here is my java.policy.applet.
    In eclipse no error, but in web browser i got same error....In cmd when i write appletviewer run.html i got this error.
    when i write in cmd that:appletviewer -J-Djava.security.policy=java.policy.applet run.html its run program perfect...
    maybe I need something else to do ?

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Applet for web browser

    in web browser i got same error
    Where does the browser try to write the file? I tried with 3 browsers and each tried to write to a different place.
    Try using a full path instead of a relative path to control where the file is being written.

    How do you update the .java.policy file? I don't know anything about a java.policy.applet file. The .java.policy file is used by the java program. I update it with the policytool program.
    If you don't understand my response, don't ignore it, ask a question.

  3. #23
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    ok I changed to this:
    Java Code:
    String myFile = "C:\'Users\'Jet\'workspace\'Trying\'bin\'dd.txt";
    but I geting same error :/(just in cmd if appletviewer run.html and in web browser)

    Eclipse(compiler) creates this file: Java.policy.applet ... Maybe in code somewhere I need include java polcy file?
    Last edited by Jet; 02-01-2014 at 08:31 PM.

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Applet for web browser

    Please post the full contents of the java console showing the full error message.

    The java program uses the .java.policy file to grant permissions. The policytool program is used to update the .java.policy file.
    If you don't understand my response, don't ignore it, ask a question.

  5. #25
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    But where need to create .java.policy file ? and how to make that program used .java.policy file(mabe in cmd need write something)?
    I got same error
    Java Plug-in 10.51.2.13
    Using JRE version 1.7.0_51-b13 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Jet
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    CacheEntry[file:/C:/Users/Jet/workspace/Trying/bin/game.jar]: updateAvailable=false,lastModified=Sat Feb 01 21:23:26 EET 2014,length=1242
    0
    java.security.AccessControlException: access denied ("java.io.FilePermission" "dd.txt" "write")

    and I think is no matter if program uses eclipse created java.policy.applet file or .java.policy file....


    can you try on your own pc run my program on web browser, and write here if you dont get any errors.

  6. #26
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Applet for web browser

    This program writes a file on my hard drive:
    Java Code:
    import java.awt.*;
    import java.io.*;
    import java.applet.*;
    
    public class TestWriting extends Applet {
    
    	private static final long serialVersionUID = -3368813097822225180L;
    	String myFile = "TestWriting.txt";
        File f = new File(myFile);
        DataOutputStream dos;
    
      public void init() {
        String osname = System.getProperty("os.name");
        System.out.println("osname="+osname);
        if (osname.indexOf("Windows") != -1) {
    //      myFile="dd.txt";
        }
      }
      public void paint(Graphics g) {
       super.paint(g);
       try {
            dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(myFile),128));
            dos.writeChars("This is an Applet generated file\n");
            dos.close();
            g.drawString("Success: Writing file" + myFile, 10, 10);
          }
          catch (SecurityException se) {
            g.drawString("Write Failed: Security exception:" + se, 10, 10);
            se.printStackTrace();
            }
          catch (IOException ioe) {
              g.drawString("Write Failed:I/O exception" + ioe, 10, 10);
              ioe.printStackTrace();
          }
       }
    }
    The location is different for the different browsers:
    IE - C:\Users\Norm\Desktop\TestWriting.txt
    Firefox - C:\windows\system32\TestWriting.txt <<<< This one failed
    Chrome - absPath=C:\Users\Norm\AppData\Local\Google\Chrome\ Application\32.0.1700.76\TestWriting.txt

    I had to add the following to my .java.policy file:
    permission java.io.FilePermission "<<ALL FILES>>", "read, write";

    I removed the above and replaced it with This that worked for IE:
    permission java.io.FilePermission "C:\\Users\\Norm\\Desktop\\TestWriting.txt", "read, write";


    My html:
    Java Code:
    <HTML><HEAD><TITLE>Applet Writer</TITLE></HEAD>
    <APPLET CODE=TestWriting Archive=TestWriting.jar WIDTH=800 HEIGHT=200>
    </APPLET>
    </BODY></HTML>
    The jar file was NOT signed.
    Last edited by Norm; 02-01-2014 at 11:33 PM.
    If you don't understand my response, don't ignore it, ask a question.

  7. #27
    Jet
    Jet is offline Member
    Join Date
    Jan 2014
    Posts
    14
    Rep Power
    0

    Default Re: Applet for web browser

    thanks for your help :)... I will try to do all things which you was mentioned in your post #26... If i will get errors I will write again to this topic...
    And i have one question. You wrote what this worked for IE:"permission java.io.FilePermission "C:\\Users\\Norm\\Desktop\\TestWriting.txt", "read, write";"
    So applet worked in all browsers or not?
    and can you say how my english language? I don't think is good :/

  8. #28
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Applet for web browser

    It did not work in FF. I think it was because of where it was trying to write the file. I did not test the applet with a full path.

    The first of the two permissions in the post worked for IE and chrome. I changed the permission to the second one for a further test with IE to see if I could restrict the permission from <<ALL FILES>> to the file that was being written.
    If you don't understand my response, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Can't get this to run in browser as applet - Help
    By confusedgirl in forum New To Java
    Replies: 1
    Last Post: 02-02-2013, 03:53 AM
  2. How to run applet in a web Browser?
    By elururajesh3 in forum Java Applets
    Replies: 4
    Last Post: 11-06-2011, 09:34 AM
  3. applet working in applet viewer, not browser
    By plasticfood in forum Java Applets
    Replies: 4
    Last Post: 06-24-2011, 06:47 PM
  4. Applet not working in browser
    By gkr1989 in forum Java Applets
    Replies: 3
    Last Post: 07-03-2009, 09:43 AM
  5. applet won't run in browser...
    By shwein in forum Java Applets
    Replies: 6
    Last Post: 10-17-2008, 06:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •