3

I'm trying to put an applet into a Google site (Because Domain hosting costs money). I've got that working, it is in the site. Now, I'm completely new to this, and my question is why doesn't my applet work?

The first thing I tried was uploading all the files to Google drive and accessing them there (My applet accesses multiple text files [ONLY READS, DOESN'T WRITE]) but that gave me a magic number error because FTP was ASCII which makes the class file all stupid, or so I've researched.

Okay, so I got a website that hosts files and it chooses the FTP (it automatically did Binary for my class files and ASCII for my text files) this made it better, but apparently unsigned applets can't access files other than the class file (I think).

So, I made a .jar for my applet using jar cvf [jar name].jar [blah blah blah, class files I need and text files I need]

I uploaded it to my file hosting site, and alas - Magic number error! 2 something something a lot of numbers. at this point, my HTML code looked like this:

<applet
codebase = "[URL for jar file]"
archive = "[jar file].jar"
code = "[class file].class"
width = ###
height = ###>
</applet>

paranoid that the site's FTP client was messing with my jar, I used FileZilla to upload to my server (an I selected the binary transfer type), which still resulted in a magic number error specifically 1347093252, which is the start of a zip file I believe (If it helps, when I click on the link for this file, it does in fact download).

I've probably done something stupid, but I would like to reiterate that I'm completely new at this.

If anyone could help, that would be awesome;

Thing's I already tried: Clearing my java cache and loading the applet (from here on, assume all the thing listed end with "and loading the applet"), clearing it again, closing my browser, clearing my java cache, clearing my cache - closing my browser - clearing my cache, reloading, changing computers, changing internet connections, changing computers and internet connections.

SSaaM
  • 108
  • 10
  • Have you tried just putting your class files into a .zip file and renaming it whatever.jar ? A jar file is essentially just a .zip file and if you don't need it to be signed then why not try? – Alex W Jun 16 '12 at 23:32
  • I thought that an unsigned applet could not access any files other than the class files that it uses? When I tried having all my files separate (class1, class2, text2, text2) I kept getting permission errors even when I set file permissions (through the hosting site) to all permissions for everyone (Read, write, execute, anything) - It just kept saying that it could not access the file (which was in the same codebase and everything). – SSaaM Jun 16 '12 at 23:36
  • An unsigned applet can operate outside of the security sandbox if you launch it using JNLP – Alex W Jun 16 '12 at 23:38

1 Answers1

1

First of all, an unsigned applet can read files off of the server it came from. If you put dome text files in the same folder as your applet, the applet can grab then. I think the method is something like getDocumentBase to get the directory your applet wad loaded from. What you cannot do us access the local file system. Making jar files with the command line is a pain. You might want to use an IDE like netbeans to build your project.

Thorn
  • 4,015
  • 4
  • 23
  • 42
  • Well, at first I had just my .class file in the same directory as the text files and things I repeatedly got this error : AccessControlException: access denied ("java.io.FilePermission" "text1.DAT" "read") Note, I used DAT files because txt are only allowed to be hosted by people who pay for the server use (DAT files worked when I ran the applet in the Virtual machine). – SSaaM Jun 17 '12 at 00:16
  • Maybe the web server is refusing to send .DAT files because it doesn't have that line type registered. Try loading a DAT file with your browser. If you can only serve html files, use that. It's just text. – Thorn Jun 17 '12 at 13:41
  • I meant Myme type above. (Web servers are given a list of supported files they are willing to serve) For an example of what I mentioned and a discussion of the security model, see http://inetjava.sourceforge.net/lectures/part2_applets/InetJava-2.3-Applet-Communication-Abilities.html. – Thorn Jun 17 '12 at 13:48