java(script) filter help me please!
July 5, 2007 8:28 AM   Subscribe

Javafilter: Can a Java Applet that runs on my website save and edit files on my website?

Basically what I need to do is have a javascript app call out a java program with some variables as arguments, then the java applet would save them to a file on my website.
I'd also like to use a java applet to read said file from my website and convey certain variable to the javascript program for display in the webpage.
Do I need to set certain read/write permissions for the java applet?
posted by spacefire to Computers & Internet (8 answers total) 1 user marked this as a favorite
 
Yes it can be done.

However, its not typical that an applet running in the client browser has the ability to use the normal java.io.File/java.io.FileInputStream/java.io.FileOutputStream classes to read/write files to the server computer from where it came from. Typical ways this would be done would be Web-DAV or the relatively new Atom Publishing Protocol.

A more common way that this is accomplished is that the Java applet uses HTTP to request the file in question and then when it is time to save the file back to the server, the applet uses HTTP to POST the data to code running on the web server. This could be anything from a Java Servlet to a CGI program to Ruby/Perl/Python/etc. your pick.

As long as your applet is strickly interacting with only the server that it was downloaded from the default permission model should be fine for you.
posted by mmascolino at 8:37 AM on July 5, 2007


Wait a second - is the java applet REALLY running on your server, or in the client's browser? In what way is it running on your server?

If you're embedding the applet in a web page via the APPLET tag or the OBJECT tag, then it's running in the client's browser. Any file IO, if it were allowed, would be on the client's computer, not yours.
posted by RustyBrooks at 9:29 AM on July 5, 2007


Response by poster: oops....I guess it wouldn't work then? The files would be hosted on my website, thus on the server.
I guess there is no need to even use Java at all, since I would have to use another scripting language besides Javascript anyway. I used something called 'ssh' under unix a long time ago to gather data from forms and email it or save it, my memory of it is really foggy, but I'm sure it would be easier using that than trying to learn something new...so I guess the question should be how do I go about doing the saving? :)
posted by spacefire at 10:11 AM on July 5, 2007


Applets do not "run" on a website.

You've confused APPLET and SERVLET; an APPLET is a bit of Java that downloads then executes on the client's browser, a SERVLET is a bit of Java executing on the server.

What you've described could be done easily by a servlet, assuming you can run Java on your server. Other common server-side options are PHP, perl.
posted by Artful Codger at 11:11 AM on July 5, 2007


SSH is an application that lets you connect to other computers in a really, really secure fashion. I don't quite see how it would play into this.

It sounds like you might want to think about Ajax?
posted by tmcw at 12:12 PM on July 5, 2007


Response by poster: ok...I am confused I guess :)

can someone give me an example of an app (regardless of language) that is called from a javascript program to save/read files from the server?

I am using it with the AJAX Yahoo Maps IDE, maybe I don't need an external app? I didn't see any commands that allow writing/reading of just any files.
posted by spacefire at 12:48 PM on July 5, 2007


Response by poster: looks like PHP is the name of the game, it can edit files. Now I need to figure out how to call out a PHP script from an AJAX/Javascript ...script with parameters and also be able to read the result, as if the PHP were a regular function.
posted by spacefire at 1:20 PM on July 5, 2007


I believe a java applet could open a connection from the client back to the server. The applet and the corresponding process on the server could then do whatever they needed (edit or save some file on the server). You might need a custom program on the server depending on what you wanted to do. disclaimer: it's been a few years since i've written a java applet.
posted by DarkForest at 2:55 PM on July 5, 2007


« Older Advice for newbie systems administrator?   |   How do I hire a landscaper in suburban Chicago? Newer »
This thread is closed to new comments.