Results 1 to 8 of 8
  1. #1
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Applet writer task

    Hello,
    I have a need for something special. I have a javascript code that sets specific parameters to variables. Let`s say this:
    Java Code:
    document.getElementById("calculate").onclick = function(e) {
         document.getElementById('parameter').value = document.getElementById('total').value;
    }
    
    <applet
     code="Printer" height="0" width="0">
     <param id='parameter' name='parameter' value="">
    </applet>
    I won`t describe the full HTML file, but let`s say - we press a button that sends some text/integer to applet tag`s param tag`s value. Which works. What I need is: how to make the java class file to listens where this has been changed and to 'write' it to a file. Let`s saay:
    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    
    public class PrintMe {
       public void printMe() {
          String s = this.getParameter("parameter");
          if ( !s.equals("") ) {
                record(s);
           }
         else {
               printMe();
         }
       }
      public void recordMe(String s) { 
          try {
             BufferedWriter bf = new BufferedWriter( new FileWriter(".datafile2"));
             bf.write(s);
             bf.close();
           } catch(Exception e) { /* do nothing */ }
         }
    
       public static void main(String[] args) {
          Printer p = new Printer();
          p.printMe();
       }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,407
    Rep Power
    20

    Default Re: Applet writer task

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,407
    Rep Power
    20

    Default Re: Applet writer task

    Note that a public static void main(String[] args) method has no significance in the context of an Applet.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Applet writer task

    I can`t seem to get it working... it just does not records me a file...

  5. #5
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Applet writer task

    I cant`t seem to bypass the java security access control of write files to hdd. Any info how to allow it? The appletviewer showed me the exception handler. :( Suggestions on how to make it work?

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Applet writer task

    Don't hide away the Exception (line #20) but let it print its stack trace.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Applet writer task

    I saw the exception but it does not helped me. The file still is not written to filesystem. The exception says:
    Java Code:
    java.security.AccessControlException: access denied ("java.io.FilePermission" "/home/ilian/data2.txt" "write")
    Any idea how to solve it?

  8. #8
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Applet writer task

    It`s useless effort, actually. I`ve found a way using JS and HTML5`s localStorage to do what I needed.

Similar Threads

  1. Help me Index writer for Ngram
    By phongtvcc in forum Lucene
    Replies: 0
    Last Post: 03-26-2012, 04:27 PM
  2. Java and Writer
    By wing in forum New To Java
    Replies: 11
    Last Post: 08-19-2011, 10:27 AM
  3. Encoding in java.io.writer
    By hariharabalan in forum New To Java
    Replies: 1
    Last Post: 12-06-2010, 10:27 AM
  4. CSV file writer
    By nida in forum Java Servlet
    Replies: 3
    Last Post: 05-08-2009, 02:08 PM

Tags for this Thread

Posting Permissions

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