-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Teh,
Teh Noranis Mohd Aris wrote: > Now, a file name that was input by the user > was created BUT the problem is that, when I open the file, the word > "null" was written to the file NOT the file content. You probably have a null content variable. String.valueOf(null) returns "null", so that's probably what's happening. > The filename > parameter was sent from the applet to the servlet BUT the file > content parameter was not sent. You're going to want to fix that. > This means that the file content > parameter does not exist and the servlet did not receive the file > content parameter! Sounds about right. If I were you, I would modify my program to do nothing if there's no file content parameter. (Well, I would actually use PUT and place the content in the body of the request, but...). > servletUrl = new URL(servletName + "?filename=" + filename); > con = servletUrl.openConnection(); > con.setDoOutput(true); > con.connect(); So far so good. > ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); > DataOutputStream out = new DataOutputStream(byteOut); > out.writeUTF(teditor); > out.flush(); > out.close(); Uhh... you put your data into a ByteArrayOutputStream and then did nothing with it at all. You need to write it to the URLConnection's OutputStream: If you are going to be using UTF, you need to specify that when connecting to your server so it knows what character set you are using. Use the "Content-Type" header for this: con.setRequestProperty("Content-Type", "text/plain; charset=UTF-8"); DataOutputStream uses "modified" UTF-8, and is actually intended to be used with Java object serialization. Don't do this. Instead, use real UTF-8 like this: Instead of the above, do this: OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(), "UTF-8")); out.write(teditor, 0, teditor.length()); out.flush(); out.close(); > DataInputStream in = new DataInputStream(con.getInputStream()); > in.close(); To be correct, you ought to empty this inputstream before closing it. Also, if you ever hope to use non-text data, you should change your content type to "application/octet-stream" with no encoding at all (the encoding is basically "raw"). You'll also want to write bytes instead of Strings to your output stream and get rid of the OutputStreamWriter. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFF9WgG9CaO5/Lv0PARAmeOAJ9HpfJPFQxkH2MTUnFn0qWs0MZ/PwCfY1Fj GvWkPIZAvF8TDKBzPTJ+p2E= =crVh -----END PGP SIGNATURE----- --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]