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