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 How to  download file from jsp page   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to  download file from jsp page   " Watch "How to  download file from jsp page   " New topic
Author

How to download file from jsp page

Nilesh Chokhadia
Greenhorn

Joined: Sep 12, 2003
Posts: 10
Hi I want to download a file from JSP page the downloaded file is already in my application.
URL for same file is given like
response.sendRedirect("a.jsp?mFileName="+mFileName+"&mUser="+mUser+"&mpath="+directoryName);
what code I have to wrie down in a.jsp file
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
I'll write some codes that are important and neccessary to sending the binary file to the users, ok? And u have to handle the path and directory location by yourself...
response.setContentType("application/jar");
File f = new File(request.getParameter("mFileName")+request.getParameter("directoryName"));
byte[] byteArray = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(f);
is.read(byteArray);
OutputStream os = response.getOutputStream();
os.write(byteArray);
os.flush();


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to download file from jsp page