W3C home > Mailing lists > Public > www-jigsaw@w3.org > May to June 2000

download servlet

From: Debraj Das <Debraj.Das@nuvation.com>
Date: Mon, 15 May 2000 20:16:26 -0400 (EDT)
Message-ID: <40410C8BBD52D311A07C00104BC7C4A82F0E9D@IGUANA>
To: "'Roland.Mainz@informatik.med.uni-giessen.de'" <Roland.Mainz@informatik.med.uni-giessen.de>
Cc: "'www-jigsaw@w3.org'" <www-jigsaw@w3.org>
I've been using the following code (inspired by Roland Mainz's file transfer
servlet code).
I can recieve the file with no problems, but the file does not retain it's
original name.

in the example I have tried to send the file notepad.exe, but when my
browser prompts me to save the file, the original name notepad.exe is not
present.  I am prompted to download TestFileXferServlet (i.e. the name of my
servlet).  I can download the file, rename it to notepad.exe (manually) and
then run the file.  
How can I make it so that I retain the original file name during  download?

	public void doPost(HttpServletRequest req, HttpServletResponse
res)throws javax.servlet.ServletException
	{try{
	 System.out.println("sending file1.txt");
	 FileInputStream in = new FileInputStream("c:\\winnt\\notepad.exe");
	
		 res.setContentType("application/x-www-form-urlencoded");
		 res.setContentLength(26816); 
		 OutputStream out = res.getOutputStream();

		 int  readlen,
			  sentsize = 0;
		 byte buffer[] = new byte[ 1024 ];

		 while( (readlen = in.read( buffer )) != -1 )
		 {
		   // throws IOException: broken pipe when download is
canceled.
		   out.write( buffer, 0, readlen );
		   sentsize += readlen;
		 }

		 out.close();
		 in.close();

		 System.out.println("sent file1.txt");

	}catch(Exception e){}
	}

Debraj
Received on Tuesday, 16 May 2000 05:43:53 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:34 GMT