Hola,

I'm working on a personal-organizer applet and I'm having trouble saving my to-do lists. I want to save a vector that contains my table data as an object (don't feel like playing with text) and I'd like to save to the folder in my webspace where all of the applet files are (.class's, index.html, etc.).

At first I was getting "access denied" exceptions thrown at me, so I signed my .jar file. I then managed to figure out that I could use the <url>.openStream() method to load and also the URLconnection to get an output stream and now the load is working, but the save is not. It doesn't throw any exceptions or say that I'm doing anything wrong, but alas new items aren't being saved.

My save function:

public static void saveDataURL(URL u)
{
     URLconnection urlCon= u.openConnection();
     urlCon.setDoOutput(true);
     urlCon.connect();

     OutputStream fout = urlCon.getOutputStream();
     ObjectOutputStream oos = new ObjectOutputStream(fout);

      oos.writeObject(<vector of data>);

      oos.close();
}

I think the problem might have to do with the way I'm using an OutputStream instead of a FileOutputSteam as the argument when instantiating the ObjectOutputStream, but I could be wrong. (I modified this method to use URLS. When I was writing to the the local hard drive, I created a FileOutputStream from a File...)

I also tried something like

...  
FileOutputStream fout = (FileOutputStream) urlCon.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(fout);

...but I believe the compiler didn't think that was too bright of an idea.

Any help would be appreciated. Any speed in replying would also be appreciated. I've had my applet working for quite some time, but I can't use it yet and am beginning to become frustrated.

Thanks.
George.

You almost certainly do not have write permission to the remote location.
And if you do have write permission there's an extremely serious security hole in your server which allows any cracker to come in and take over at any time.

Maybe if the URL is running a server that accepts connections from a certain port that might be possible.
--
dein vater

Thanks for the replies guys, but here's the thing: I don't know very much about the backend side of things. I'd like to store my saved information in a central location so that I can use my applet everywhere. I thought storing a file in the same location where the applet itself is located was logical and that there'd have to be a way to write to this location.

This seems like a relatively basic goal, so there HAS to be a simple way to do this.

All I want to do is read/write an object (A vector) from/to a file on the server where my applet is stored.

Can it be done? (yes) If so, how?

Pretty Please...with sugar on top.

Hi everyone,

I have some experience on this. You see usually when you are writing to a URL it most definately requires a username and password before you can write to that server.

You see some hosts when you want to use their site they require you to use their own uploading program as their are not using the RFC and using something custom.

But for argument sake let's assume that your host conforms to the RFC.
Now you will need to use the Authenticator class that will allow you to authenticate to you site and save your program there.

But not all servers do this and some of them put the password and username as part of the URL as such

http://username:password@http.fileplanet.com/polo.zip

When you put this address in the URL class you will be able to connect.

A good example is ftp servers as a lot of them use this format wherethe username and password is part of the URL

Richard West

Hi everyone,

I noticed that you said that you were using an applet. I think that this may cause some security restrictions. If i were you i would prefer to do it as an application where there are practically no restrictions

Richard West

Hi everyone,

Did it work??

Richard West

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.