944,085 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3659
  • Java RSS
Sep 14th, 2005
0

Writing Files to URLs

Expand Post »
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:

Java Syntax (Toggle Plain Text)
  1. public static void saveDataURL(URL u)
  2. {
  3. URLconnection urlCon= u.openConnection();
  4. urlCon.setDoOutput(true);
  5. urlCon.connect();
  6.  
  7. OutputStream fout = urlCon.getOutputStream();
  8. ObjectOutputStream oos = new ObjectOutputStream(fout);
  9.  
  10. oos.writeObject(<vector of data>);
  11.  
  12. oos.close();
  13. }

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

Java Syntax (Toggle Plain Text)
  1. ...
  2. FileOutputStream fout = (FileOutputStream) urlCon.getOutputStream();
  3. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
deineMutti is offline Offline
9 posts
since Jun 2005
Sep 15th, 2005
0

Re: Writing Files to URLs

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Sep 15th, 2005
0

Re: Writing Files to URLs

Maybe if the URL is running a server that accepts connections from a certain port that might be possible.
--
dein vater
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Sep 15th, 2005
0

Re: Writing Files to URLs

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
deineMutti is offline Offline
9 posts
since Jun 2005
Sep 16th, 2005
0

Re: Writing Files to URLs

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

Java Syntax (Toggle Plain Text)
  1. 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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Sep 16th, 2005
0

Re: Writing Files to URLs

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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Sep 20th, 2005
0

Re: Writing Files to URLs

Hi everyone,

Did it work??

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: accessing redirected pages through java crawler
Next Thread in Java Forum Timeline: can anyone help me





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC