Dear All,
   
  First, thank you so much for the reply, Mr. Christopher Schultz. In my 
program, I want the servlet to load an applet where I can input the file name 
in a given text field and the file content in a given text area. When the user 
has input the information, I want to POST the file name and its content from 
the applet to the servlet. The servlet will then GET the parameters (file name 
and file content) from the applet and save the file content in C:/temp/ based 
on the file name that has been input. I do not know whether I pass the 
parameters from the applet to the servlet correctly. After I input the file 
name and the file content, 2 files were created by the system:
  1. a file with the name null
  2. a source code file with a file name from the user input with no content at 
all.
   
  The system should only create one file with a file name and the file content 
based on the user input. The main problem is that 2 files were created. One 
question that was asked to me is "Why are you saving a file AND serving a page 
in the same servlet?" Yes, I'm using the same servlet to save a file and 
serving a page to save files. What is actually the matter with that approach? 
Another question was about "What you want is a POST with the content of your 
file in the request body -- NOT in the request parameters". Can you please 
elaborate the statement? How should I actually solve this problem? Please 
explain in detail. I'm really waiting for a prompt reply. Thank you so much.
   
  Yours Sincerely,
  TEH NORANIS    

Christopher Schultz <[EMAIL PROTECTED]> wrote:
  -----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("");
> out.println("");
> out.println("");
> out.println("    Save File To Server");
>
> ...

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: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



 
---------------------------------
Access over 1 million songs - Yahoo! Music Unlimited.

Reply via email to