下载后,Jar文件已损坏

时间:2022-07-23 19:41:14

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?

我刚刚创建了一个小的jsp文件,我从weblogic服务器下载了一个jar文件,它通过eclipse安装在我的计算机上,使用我从网上抓取的以下代码。但是当我尝试使用jar文件时,它说它已经损坏了。原始和下载的jar文件的大小是相同的。我可以使用代码下载和打开文本文件。代码有什么问题?

  <%    
  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();   
  %>   

1 个解决方案

#1


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

尝试将content-type更改为application / java-archive。还要设置content-length标头以包含文件的大小。

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.

另外,我建议您使用一些校验和工具(如md5sum)来验证文件下载比较,而不是依赖于要比较的大小。

#1


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

尝试将content-type更改为application / java-archive。还要设置content-length标头以包含文件的大小。

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.

另外,我建议您使用一些校验和工具(如md5sum)来验证文件下载比较,而不是依赖于要比较的大小。