Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can Applet write file on remote server?

4 views
Skip to first unread message

erida...@my-deja.com

unread,
Aug 7, 2000, 3:00:00 AM8/7/00
to
Ciao everybody.

My question is very simple :
"Can an Applet write a file on remote system?"
(I wrote the following applet, I downloaded and installed an application
that makes my PC as a server - the pgm is Savant 2.1) but..it doesn't
work.
-------------------------- My applet --------------------------
import javax.swing.JApplet;
import java.net.*;
import java.io.*;

public class hello_world_applet1 extends JApplet {

public int counter;

public void init() {
try {
counter = new DataInputStream(new FileInputStream(new
URL(getCodeBase()+"images/counter.int").getPath())).readInt();
counter++;
DataOutputStream DOS = new DataOutputStream(new FileOutputStream
(new URL(getCodeBase()+"images/counter.int").getPath()));
DOS.writeInt(counter);
}
catch (IOException e) {
System.err.println(e);
}
}

public void start() {
}

public void stop() {
}

public void destroy() {
}
}
---------------------------------------------------------------

Below, messages from java console :
-------------------------- java console -----------------------
JAR cache enabled.
Opening http://it026570.italy.ibm.com/hello_world_applet1.class with
cookie "w3ibmTest=true".
http://it026570.italy.ibm.com/index.html
java.security.AccessControlException: access denied
(java.io.FilePermission /index.htmlimages/counter.int read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at hello_world_applet1.init(hello_world_applet1.java:12)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
---------------------------------------------------------------

Thank you in advance.

Cella Ivan


Sent via Deja.com http://www.deja.com/
Before you buy.

Thomas Papendieck

unread,
Aug 7, 2000, 3:00:00 AM8/7/00
to
Hi Ivan,

erida...@my-deja.com schrieb:

> Ciao everybody.
>
> My question is very simple :
> "Can an Applet write a file on remote system?"

No!

>
> (I wrote the following applet, I downloaded and installed an application
> that makes my PC as a server - the pgm is Savant 2.1) but..it doesn't
> work.

Why don't you have your server application dealing with the files?

The ????InputStream and ????OutputStream klasses kan only handle local
(mountet) ressources. But appletts are forbidden to use them.

build a socket-connection between applet and Server an let the server
application access the files.

> [...]

MfG
Thomas Papendieck

eMail is as private as a post card - Please encrypt your answer!
PGP key available at: pgp.ai.mit.edu - port: 11371
ID: 0x273C213E
finger print: 4CB3 2D02 802A 3DA6 0499 0768 4CB1 D301 273C 213E


0 new messages