This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile 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