• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet on website

 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to put an applet on a personal website that needs access to some text files (which are in the same folder as the class file).
The applet loads up fine into the html page but when it tries to complete its process using the text files nothing happens!
Should I have any special class files, jar's or something in that web folder to allow the applet to operate?
Thanks in advance.
[More info added]
I just discovered it doesnt work in IE or NS on local either ( guess I should have done my homework before posting!! ) so the problem is obvoiusly not the web folder contents. The applet runs perfectly well in appletviewer though.
Perhaps the problem is accessing the text files ( I'm using a RandomAccessFile with the 'r' parameter for read only)
Terry
[This message has been edited by Terence Doyle (edited July 04, 2001).]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing that you have to remember is that the applet is running in the clients web browser, not on the server! You could do one of two things:

  • JAR up the applet and the text files so all get downloaded to the client machine, use the getClass() method on your applet to return a Class object of your applet and use getResourceAsStream()... you'll have to read up on this in the API... basically this will let you open the text file from your JAR file as an InputStream.
  • You can also specify the URL to your text files on the server and use openStream() on the url object to open an InputStream from your text file.


  • Either of these should work fine... you would probably want to use the first if the contents of the files are supposed to remain static, the second if there was the chance the files would be updated ( not updated through the applet, of course... that would require a signed applet... however, I believe you specified you wanted to open these as 'read-only' so that shouldn't matter. ).

    HTH,
    -Nate
    [This message has been edited by Nathan Pruett (edited July 05, 2001).]
    [This message has been edited by Nathan Pruett (edited July 05, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic