tags:

views:

59

answers:

3

I have a java applet that runs fine locally on my desktop computer. but when I put it on my linux web server its works but the save file feature is save the file to the web browser temp folder and not to the web server.

<applet name="rapplet" type="applet" archive="applets.jar" 
     code="acap.class" codebase="." height="96" width="150"> 
<param name="msg" value="test.snd" />
+3  A: 

A Java applet runs in the client browser and not on the server which explains why you cannot save files to the server.

Darin Dimitrov
I've seen java photo upload apps that save photos to the web server. What my app is doing is just recording sound. is there any way to have output save to the server, like how flash (without flash server) does it for image, sound and video apps.
acctman
A: 

If an applet at your site could save bytes directly to the server, then a trusted applet on other people's sites (or many other types of apps.) could also do that.

If someone were being malicious they might dump a couple of gigabytes to your server, leading to all sorts of problems.

For that reason, the server needs to protect itself from such denial of service attacks, and all uploads need to be done through an interface that your server specifically provides. This interface might, for example, check the size of the upload and that it contains no viruses or trojans.

Andrew Thompson
+3  A: 

You need:

  • server-side code to handle file-upload. Look at java servlets and commons-fileupload
  • the applet must send the files over HTTP. You can do this with Apache HttpClient

Update: you seem to have missed the point of Java applets - they run on the client. In the browser, that is. They have absolutely nothing to do with servers. If you want to have any communication with a server, you need some protocol - it could be HTTP (as I suggested), it could be plain sockets, or any other protocol that suits you.

Bozho
I would need tomcat installed on my server to get any servlets to run?
acctman
yes. or any servlet container. If you don't want, you can have a php script to handle the upload.
Bozho
php code to handle the upload from the java applet? I can stop the file from uploading locally to my computer and make it save to the server with php code?
acctman
yes. applet is client-side, and it should transfer the file to the server, if you want it there.
Bozho
can you give me an example of how to do that with php?
acctman
there are tons of examples on the web.
Bozho
that was the first thing I did before posting here. i type "java applet php save file" not finding much help
acctman
results for "php upload file", I guess. As I said the the applet runs on the client, so it does not matter to the server-side component.
Bozho
I read that there must be a URLConnection / HTTP Protocol in the java class / applet in order to write a file to a server. Is this true? so does that have to be done on top of the backend coding for php? I'm a bit confused some people say java applets can and some say it can't without servlets or something.
acctman
yes - use URLConnection in the applet to connect to whatever server side script you want - be it PHP or servlet
Bozho