Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

jsp code to download zip file by clicking the link

807603Nov 20 2007 — edited Nov 20 2007
I have following code to download zip file ...Its downloading Zip file in d:/temp folder But its also downloading a jsp file which is empty...
And its not asking to open,save,close window for zip file...Its asking that for jsp file.Its downloading zip file if we click cancel button also ..can u please solve my problem AS SOON AS POSSIBLE.......ITS URGENT



My CODE is
------------------------------------------------------------------

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.io.BufferedReader,java.io.IOException,java.io.InputStreamReader,java.util.Enumeration,java.util.zip.*,java.util.zip.ZipFile"%>
<html>
<body>
<%
//getting the zip file path

String path=request.getParameter("path");
response.setContentType("application/zip");
//response.setHeader("Content-Disposition", "attachment; filename=\"" + path + "\"");
byte[] _buf = new byte[1024];
//zos is used to write files in zip
ZipOutputStream zos = null;
//zip is used to read files
ZipInputStream zis = null;
boolean bsuccess = true;
zos = new ZipOutputStream(new java.io.FileOutputStream("D:/temp/SSO.zip"));
zis = new ZipInputStream(new java.io.FileInputStream(path));
ZipEntry ze = null;

while ((ze = zis.getNextEntry()) != null)
{
String fname = ze.getName();
if (fname!=null)
{
//copy the entry from zis to zos
int bytes = 0;
//deal with password protected files
zos.putNextEntry(new ZipEntry(fname));
while ((bytes = zis.read(_buf)) > 0)
{
zos.write(_buf, 0, bytes);
}
zis.closeEntry();
zos.closeEntry();

}
}
if (zis != null)
zis.close();
if (zos != null)
zos.close();
%>
</html>
</body>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2007
Added on Nov 20 2007
6 comments
2,645 views