User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 403,403 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,602 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 2419 | Replies: 8
Reply
Join Date: Mar 2008
Location: India
Posts: 4
Reputation: Mahesh59 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Mahesh59's Avatar
Mahesh59 Mahesh59 is offline Offline
Newbie Poster

downloading files using jsp

  #1  
Apr 6th, 2008
i'm able to upload files using jsp into my server.Now i want to download those files with a popup window showing open save or cancel options.can anyone tell me the code for it.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2006
Location: India
Posts: 56
Reputation: shaikh_mshariq is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
shaikh_mshariq's Avatar
shaikh_mshariq shaikh_mshariq is offline Offline
Junior Poster in Training

Re: downloading files using jsp

  #2  
Apr 7th, 2008
You want to download Files from the server using jsp page ? If You want a file browser in jsp than you should search on google for Browser.jsp created by Taylor Bastien, David Levine, David Cowan
It has all the thing you require. I cant paste its code here because it is too long search for browser.jsp + its authors name u will find it. I hope this have solved your query partially other pop up window stuff yet there.
Ideas are the building blocks of Ideas

Jason Zebehazy
Reply With Quote  
Join Date: May 2008
Posts: 3
Reputation: Sprashant is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Sprashant Sprashant is offline Offline
Newbie Poster

Re: downloading files using jsp

  #3  
May 12th, 2008
i'm able to upload files using jsp into my server.Now i want to download those files with a popup window showing open save or cancel options.can anyone tell me the code for it.[/quote]
Reply With Quote  
Join Date: Mar 2008
Location: India
Posts: 4
Reputation: Mahesh59 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Mahesh59's Avatar
Mahesh59 Mahesh59 is offline Offline
Newbie Poster

Re: downloading files using jsp

  #4  
May 15th, 2008
  1. <!-- upload.jsp -->
  2. <%@ page import="java.io.*" %>
  3. <%
  4. String contentType = request.getContentType();
  5. System.out.println("Content type is :: " +contentType);
  6. if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
  7. {
  8. DataInputStream in = new DataInputStream(request.getInputStream());
  9. int formDataLength = request.getContentLength();
  10. byte dataBytes[] = new byte[formDataLength];
  11. int byteRead = 0;
  12. int totalBytesRead = 0;
  13. while (totalBytesRead < formDataLength)
  14. {
  15. byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
  16. totalBytesRead += byteRead;
  17. }
  18. String file = new String(dataBytes);
  19. String saveFile = file.substring(file.indexOf("filename=\"") + 10);
  20. //out.print("FileName:" + saveFile.toString());
  21. saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
  22. //out.print("FileName:" + saveFile.toString());
  23. saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
  24. //out.print("FileName:" + saveFile.toString());
  25. //out.print(dataBytes);
  26. int lastIndex = contentType.lastIndexOf("=");
  27. String boundary = contentType.substring(lastIndex + 1,contentType.length());
  28. //out.println(boundary);
  29. int pos;
  30. pos = file.indexOf("filename=\"");
  31. pos = file.indexOf("\n", pos) + 1;
  32. pos = file.indexOf("\n", pos) + 1;
  33. pos = file.indexOf("\n", pos) + 1;
  34. int boundaryLocation = file.indexOf(boundary, pos) - 4;
  35. int startPos = ((file.substring(0, pos)).getBytes()).length;
  36. int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
  37. saveFile = "D:\\java\tomcat5\\webapps\\ROOT\\images\\" + saveFile;
  38. FileOutputStream fileOut = new FileOutputStream(saveFile);
  39. //fileOut.write(dataBytes);
  40. fileOut.write(dataBytes, startPos, (endPos - startPos));
  41. fileOut.flush();
  42. fileOut.close();
  43. out.println("File saved as " +saveFile);
  44. }
  45. %>
this it the jsp code.In this u can only upload .doc & image files.



Html file for this is

  1. <html>
  2. <head></head>
  3. <body background="bgcircle.gif">
  4. <form method="post" action="products.jsp" name="upform" enctype="multipart/form-data">
  5. <table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
  6. <tr>
  7. <td align="left">
  8. <b><font color="white">Select a file to upload :</b></td>
  9. </tr>
  10. <tr>
  11. <td align="left">
  12. <input type="file" name="uploadfile" size="50">
  13. </td>
  14. </tr>
  15. <tr>
  16. <td align="left">
  17. <input type="hidden" name="todo" value="upload">
  18. <input type="submit" name="Submit" value="Upload">
  19. <input type="reset" name="Reset" value="Cancel">
  20. </td>
  21. </tr>
  22. </table>
  23. </form>
  24. </body>
  25. </html>
Last edited by peter_budo : May 15th, 2008 at 4:23 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,701
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: downloading files using jsp

  #5  
May 15th, 2008
YUCK, scriptlets.
Use servlets for anything requiring Java code.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Jun 2008
Posts: 1
Reputation: cecy_115 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cecy_115 cecy_115 is offline Offline
Newbie Poster

Re: downloading files using jsp

  #6  
Jun 6th, 2008
Hi mahesh i just went through ur code,for downloading you can just save the filepath in the database and display witihn the links wen you click theh link you will get the download dialog box..../
Reply With Quote  
Join Date: Jun 2008
Posts: 1
Reputation: smishra1985 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
smishra1985 smishra1985 is offline Offline
Newbie Poster

Re: downloading files using jsp

  #7  
Jun 14th, 2008
hi can u tell me how to provide connectiviity between Servlet and database
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,701
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 195
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: downloading files using jsp

  #8  
Jun 15th, 2008
we don't help thread hijacking kiddos.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,249
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 10
Solved Threads: 271
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: downloading files using jsp

  #9  
Jun 15th, 2008
Originally Posted by smishra1985 View Post
hi can u tell me how to provide connectiviity between Servlet and database

Sun's tutorials on Java spell it all for you
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 9:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC