File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem with Jar download code in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem with Jar download code in servlet" Watch "Problem with Jar download code in servlet" New topic
Author

Problem with Jar download code in servlet

Thirugnanam Saravanan
Ranch Hand

Joined: Dec 13, 2007
Posts: 81
Hi All,

I have tried this code from Head First book ( Chapter 4 ) to implement the jar download functionality in servlets. The code is working fine, but while downloading the file,it is not getting downloaded as jar file( with .jar extension). Instead it is getting downloaded as a file with unknown filetype. What's wrong with this code? What should I do to implement my code in such a way that, when i download, it should be downloaded as a .jar file? Any Ideas?


[ November 18, 2008: Message edited by: Thirugnanam Saravanan ]

Saravanan
SCJP 5.0(98%), SCWCD 5.0 (100%), OCA
cesar valencia
Ranch Hand

Joined: Oct 14, 2008
Posts: 33
Originally posted by Thirugnanam Saravanan:
Instead it is getting downloaded as a file with unknown filetype. What's wrong with this code? What should I do to implement my code in such a way that, when i download, it should be downloaded as a .jar file? Any Ideas?


set the "content-disposition" header, like this:



just replace that with the filename and you're set.


scjp5, scwcd5
Thirugnanam Saravanan
Ranch Hand

Joined: Dec 13, 2007
Posts: 81
Thanks . Now it works
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi, Can you please let me know why do we need [B] and [/B> here


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1629
    
  23

Hi, Can you please let me know why do we need [B] and [/B> here

That is a small mistake: they don't need to be there

Regards,
Frits
 
 
subject: Problem with Jar download code in servlet
 
Similar Threads
code for file download
Read operation over URLConnection is stuck!
Doubt in HTTPServletResponse
problem running the download JAR application
download file using OutputStream from Servlets