The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

file downloading

Posted by krnbhaskar on September 04, 2000 at 2:25 AM

I had written following Java Download Servlet and which is working fine with Netscape but not with Internet Explorer. Problem with Internet Explorer is that while Downloading file, Instead of taking File Name it takes Servlet Name for file Downloading...
Any body has any clue, where I am wrong in this??

Thank you very much in advance.

bhaskar

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class fileDownload extends HttpServlet {

public void doGet(HttpServletRequest req ,HttpServletResponse res)
throws IOException,ServletException {
try{
doPost(req,res);
}catch(Exception e){e.printStackTrace();}
}

public void doPost(HttpServletRequest req ,HttpServletResponse res)
throws IOException,ServletException {

res.setContentType("application/x-filler");
HttpSession session = req.getSession(true);

try {
String fileName= req.getParameter("filename");
String filePath = req.getParameter("filepath");
String downloadFile = filePath + fileName;
//String userName = (String) session.getValue("login_name");
String download_date = "sysdate";

res.setHeader("Content-Disposition","attachment; filename=\"" + downloadFile + "\";");

ServletOutputStream stream = res.getOutputStream();

BufferedInputStream fif = new BufferedInputStream(new FileInputStream(downloadFile));
int data;
while((data = fif.read()) != -1)
{
stream.write(data);
}
fif.close();
stream.close();
}

catch(Exception e) {
e.printStackTrace();
}

finally {
try{

} catch (Exception ignore) {}
}

}
}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us