Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to download file from jsp page

 
Nilesh Chokhadia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic