简体   繁体   中英

Jar file is corrupt after downloading

I have just created small jsp file in which I am downloading a jar file from weblogic server that is installed in my computer through eclipse using the following piece of code which I grabbed from net. But when I try the jar file, it says it is corrupt. The sizes of original and downloaded jar files are identical. I can download and open text files using the code. What is wrong in the code?

  <%    
  String filename = "Words2.jar";   
  String filepath = "C:\\Users\\OD00259\\Desktop\\";   
  response.setContentType("APPLICATION/OCTET-STREAM");   
  response.setHeader("Content-Disposition","attachment; filename=\"" +  
  filename + "\"");   

  java.io.FileInputStream fileInputStream=new java.io.FileInputStream
  (filepath + filename);  

  int i;   
  while ((i=fileInputStream.read()) != -1) {  
  out.write(i);   
  }   
  fileInputStream.close();   
  %>   

Try Change the content-type to application/java-archive. Also set the content-length header to include the size of the file.

Also, I would recommend you to use some checksum tools like md5sum for verifying the file downloads comparison instead of relying on the size to compare.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM