In my application , I want to download any type of files with download dialog box where the content of the binary files are kept in oracle database under the blob format.
While I am trying to download the file from a portlet (using servlet), it opens the contents in browser page for known type file(.doc,.txt,.html etc), instead of giving an option for download in IE .
I am using IE 7.0.
Please find the servlet class
***************************
public class DownloadReportServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res) {
doGet(req, res);
}
public void doGet(HttpServletRequest req, HttpServletResponse res) {
TCMDao dao = (TCMDao) DAOFactory.getDAO("tcm-dao");
String uid = req.getParameterValues("uid");
ReportDto report = (ReportDto) dao.get(uid);
SimpleDateFormat dateFormat=new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss_SSS");
String generartedTime = dateFormat.format(report.getGenerationTime().getTime());
System.out.println(" Generated Time : " + generartedTime);
System.out.println(" Report Name : " + report.getName());
report.setFilename(report.getName() + "_" + generartedTime);
res.setHeader("Content-Disposition", "attachement; filename="
+ report.getFilename()+"."+ report.getReportType());
res.setContentType("application/octet-stream");
try {
OutputStream os = res.getOutputStream();
InputStream is = report.getData();
int read = 0;
byte[] bytes = new byte[1024];
while((read = is.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
os.flush();
os.close();
is.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Thanks in Advance.
Atanu