File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes send contents as attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "send contents as attachment " Watch "send contents as attachment " New topic
Author

send contents as attachment

Ramesh Bhagasra
Greenhorn

Joined: Nov 21, 2003
Posts: 8
I am able to see the blob contents in the client window but the file does not show as attachment which is my main purpose-- to give the user the option either to open the file or to save the file on his machine. I am also setting the setHeader as attachment , but nothing happens....and sometimes it shows a dialog box to open my jsp file itself rather than the desired file... sending you the code ..please help
File file1 = new File("c:\\Test.java");
byte[] buffer = new byte[(int)file1.length()];
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file1));
is.read(buffer, 0, (int)file1.length());
is.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(buffer, 0, (int)file1.length());
System.out.println(baos.toString());
byte[] pass = baos.toByteArray();
response.setHeader("Content-Desposition", "attachment;filename=untitled.java");
response.setContentType("application/octet-stream");
//Send content to Browser
ServletOutputStream servletOut = response.getOutputStream();
servletOut.write(pass);
servletOut.close();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: send contents as attachment