-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Teh,
Teh Noranis Mohd Aris wrote:
> I want to save a file name and its content to the computer server at
> directory C:/temp/. I've passed the file name and file content
> parameter from the applet to the servlet. The problem now is that the
> file name is created in the computer server directory but a 'null' is
> included in the file content. Can anyone please help me solve the
> problem why this is happening?
> servletUrl = new URL(servletName +
> "?filename="+filename+"&teditor="+teditor);
> con = servletUrl.openConnection();
> con.setUseCaches(false);
>
> BufferedReader buf = new BufferedReader(new
> InputStreamReader(con.getInputStream()));
This isn't what you want to do. What you want is a POST with the content
of your file in the request body -- NOT in the request parameters.
That isn't to say that your attempt won't work... it's just that there
are many limitations on passing information through a URL (such as any
maximum URL length limits set by your web server).
> HttpSession session = req.getSession();
> PrintWriter out = res.getWriter();
>
> out.println("<html>");
> out.println("<head>");
> out.println("<title>Login</title>");
> out.println("<center><h2>Save File To Server</h2>");
>
> ...
This is a very odd way to do things. Why are you saving a file AND
serving a page to save files in the same servlet?
> String name = req.getParameter("filename");
> String content = req.getParameter("teditor");
>
> String nameFile = "C:/temp/"+name;
> FileWriter resultsFile = new FileWriter(nameFile,true);
> PrintWriter toFile = new PrintWriter(resultsFile,true);
> toFile.println(content);
> toFile.close();
So, do you get a file in C:\TEMP\whatever? If so, what is the content of
the file. You said "a null"... do you mean a 0 byte file? Or the word
"null"?
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF6KD09CaO5/Lv0PARAph4AJ0RFetzCrvK7kylCLOjfz0s2lNtngCfVgSg
06XYsRJpi0Bn/mEjBsAnp4I=
=6KXD
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: [email protected]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]