Home > Archive > Java Help > June 2007 > Java Applet saving results on home server
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Java Applet saving results on home server
|
|
| rizwindu 2007-06-13, 8:10 am |
| Hi,
I have a Java applet that, once finished interacting with the user,
needs to save the results. I would like to be able to write a text
file with the results to the applets home server, or a specified FTP
server. I have found some FTP connection classes that allow files to
be uploaded, but these require files to be on the client computer to
upload. I believe that applets cannot write to the client computer. I
would like to be able to have some form of 'create file', 'write
contents' on the home server. Is this possbible ?
Cheers,
Ben.
P.S. A database would be one solution, but due to circumstances
outside of my control this is not really an option.
| |
| Andrew Thompson 2007-06-13, 8:10 am |
| rizwindu wrote:
...
>I have a Java applet that, once finished interacting with the user,
>needs to save the results. I would like to be able to write a text
>file with the results to the applets home server, or a specified FTP
>server. I have found some FTP connection classes that allow files to
>be uploaded, but these require files
Class files? Configuration files? What files?
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.as...-setup/200706/1
| |
| rizwindu 2007-06-13, 8:10 am |
| On Jun 13, 12:26 pm, "Andrew Thompson" <u32984@uwe> wrote:
> rizwindu wrote:
>
> ..
>
>
> Class files? Configuration files? What files?
>
> --
> Andrew Thompsonhttp://www.athompson.info/andrew/
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-setup/200706/1
Either would do really. Could store the results in a class and write
that. I can also store the results to a string and write that to a
file.
| |
| Gordon Beaton 2007-06-13, 8:10 am |
| On Wed, 13 Jun 2007 11:01:32 -0000, rizwindu wrote:
> I have a Java applet that, once finished interacting with the user,
> needs to save the results. I would like to be able to write a text
> file with the results to the applets home server, or a specified FTP
> server. I have found some FTP connection classes that allow files to
> be uploaded, but these require files to be on the client computer to
> upload.
With the Jakarta Commons FTP client:
OutputStream os = FTPClient.storeFileStream("remoteName");
....then write your data to the resulting OutputStream. You don't need
a local file.
/gordon
--
| |
|
| rizwindu wrote:
"Andrew Thompson" wrote:[color=darkred]
rizwindu wrote:[color=darkred]
> Either would do really. Could store the results in a class and write
> that. I can also store the results to a string and write that to a
> file.
On the face of it that doesn't make sense. What sort of "results" are you
getting, and how to you envision that it would be stored to a class? Are
these results bytecode?
If they are bytecode, then how do you envision they be encoded into a String?
--
Lew
| |
| rizwindu 2007-06-13, 7:26 pm |
| On Jun 13, 2:00 pm, Lew <l...@lewscanon.nospam> wrote:
> rizwindu wrote:
> "Andrew Thompson" wrote:
> rizwindu wrote:
>
> On the face of it that doesn't make sense. What sort of "results" are you
> getting, and how to you envision that it would be stored to a class? Are
> these results bytecode?
>
> If they are bytecode, then how do you envision they be encoded into a String?
>
> --
> Lew
Lew:
My results are a mix of strings, arrays etc. I can write them to a
file by outputting the text nicely. Or I can make a 'Results' class
that has some data structures to store all the things I need, then I
can create a new Results object, and save the results object.
Gordon:
I'll look into the FTP client. From the example you gave looks like it
might be what I need. Thanks.
Ben.
| |
|
| rizwindu wrote:
"Andrew Thompson" wrote:
rizwindu wrote:[color=darkred]
Lew wrote:[color=darkred]
rizwindu wrote:[color=darkred]
> My results are a mix of strings, arrays etc. I can write them to a
> file by outputting the text nicely. Or I can make a 'Results' class
> that has some data structures to store all the things I need, then I
> can create a new Results object, and save the results object.
That clears up my misunderstanding. You had said you'd save it as a "class
file", but your explanation that that is not what you intend clears up the matter.
Saving an object only begs the question. You still have to decide whether to
save as raw strings, Properties or XML files, to name three text options, or
as a serialized binary object, or with some other encoding scheme (Base64,
uuencode, ...). This puts you right back into your original question.
--
Lew
| |
| rizwindu 2007-06-14, 10:10 pm |
| On Jun 13, 2:46 pm, Lew <l...@lewscanon.nospam> wrote:
> rizwindu wrote:
> "Andrew Thompson" wrote:
> rizwindu wrote:
> Lew wrote:
>
> rizwindu wrote:
>
> That clears up my misunderstanding. You had said you'd save it as a "class
> file", but your explanation that that is not what you intend clears up the matter.
>
> Saving an object only begs the question. You still have to decide whether to
> save as raw strings, Properties or XML files, to name three text options, or
> as a serialized binary object, or with some other encoding scheme (Base64,
> uuencode, ...). This puts you right back into your original question.
>
> --
> Lew
Hi,
I've got a problem with the Jakarta ftp client.
I can open a file stream and save one file to the server, but if I try
and save a second file it doesn't work.
<CODE>
// Connect and login
FTPClient ftp = new FTPClient();
ftp.connection(SERVER_IP);
ftp.login(USERNAME, PASSWORD);
// Save a text file
OutputStream text_os = ftp.storeFileStream(FILENAME + ".txt");
DataOutputStream text_dos = new DataOutputStream(text_os);
text_dos.writeChars(OUTPUT_STRING);
text_dos.close();
text_os.close();
// Save an object
OutputStream object_os ftp.storeFileStream(FILENAME + ".object");
ObjectOutputStream object_oos = new ObjectOutputStream(object_os);
object_oos.writeObject(results);
object_oos.close();
object_os.close();
// Logout and close
ftp.logout();
ftp.disconnect();
</CODE>
It saves the first stream correctly, but the second call of
ftp.storeFileStream return null, which apparently happens if "the data
connection cannot be opened (e.g., the file does not exist)".
If I change the order in which the files are written, still the first
one is written but the second isn't.
| |
| Gordon Beaton 2007-06-14, 10:10 pm |
| On Thu, 14 Jun 2007 11:08:59 -0000, rizwindu wrote:
> I can open a file stream and save one file to the server, but if I try
> and save a second file it doesn't work.
You must use ftp.completePendingCommand() after each file (this is
mentioned in the docs for storeFileStream()).
You should probably use ftp.getReplyCode() and check for a positive
result in several places as well (e.g. after logging in). Have a look
at the example in the description of completePendingCommand().
/gordon
--
| |
| rizwindu 2007-06-14, 10:10 pm |
| On Jun 14, 12:45 pm, Gordon Beaton <n...@for.email> wrote:
> On Thu, 14 Jun 2007 11:08:59 -0000, rizwindu wrote:
>
> You must use ftp.completePendingCommand() after each file (this is
> mentioned in the docs for storeFileStream()).
>
> You should probably use ftp.getReplyCode() and check for a positive
> result in several places as well (e.g. after logging in). Have a look
> at the example in the description of completePendingCommand().
>
> /gordon
>
> --
OK. I see. Cheers.
Ben.
|
|
|
|
|