Servlet writing files on server ?

P

PiotrJJ

Let assume that I want to send text from JTextArea from Applet to servlet

Like this:



URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
url = new URL (getCodeBase().toString() + "file1.txt");
urlConn = url.openConnection();

urlConn.setDoInput (true);

urlConn.setDoOutput (true);

urlConn.setUseCaches (false);

urlConn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");

printout = new DataOutputStream (urlConn.getOutputStream ());
String content = jtextarea.getText();
printout.writeBytes (content);
printout.flush ();
printout.close ();



How should servlet source code luck like that receiveing data and writing it
to file1.txt on server?



Do servlets can writes files on server witch they are on ?? How do they
recognize file system ??

Or maybe that should cgi script do ??

If yes how should I write it?

This is the primary topic.

_________________________________________

2.

It would be nice if servlet can recognize session and writes data for the
session 1 to file1.txt - for the session 2 to file2.txt.

Like on chats. When first user log on chat, all what he says -servlet will
save to file1.txt then if he or someone else log again the conversation will
be save to file2.txt.



Thanks for help and sorry for my English.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,164
Latest member
quinoxflush
Top