Hi,
Trying to download zipOutPutStream created with data from database in
JSP , I am getting a error "Client terminated connection to server before the entire response was sent. Status code: -1". Any one have idea on this problem.
Given below is the snipnet of the code.
<%@ page contentType="text/zip"%>
<%@ page import="com.zip.fr.*,java.sql.*,javax.sql.*,javax.naming.*,java.io.*,java.util.zip.*" session="true"%>
<%
//************** Get Connection to DB2
DataSource ds = null;
Connection con = null;
try
{
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("jdbc/xxx");
con = ds.getConnection("yyyyy", "zzzzz");
System.out.println("using my connection");
}
catch (SQLException errSQL)
{
//hhhhhh
}
catch(Exception errException)
{
//yyyy
}
try
{
String headerName = "header.txt";
String fileName = "test.txt";
//************** Get Current Date
java.util.Calendar c = java.util.Calendar.getInstance();
String ccyy = "" + c.get(java.util.Calendar.YEAR);
String mm = "" + (c.get(java.util.Calendar.MONTH) + 1);
if (mm.length() == 1)
{
mm = "0" + mm;
}
String dd = "" + c.get(java.util.Calendar.DAY_OF_MONTH);
if (dd.length() == 1)
{
dd = "0" + dd;
}
//************** Establish Output Stream
OutputStream os = response.getOutputStream();
ZipOutputStream zos = new ZipOutputStream(os);
//************** Create Header Entry into Zip File
ZipEntry zipEntry1 = new ZipEntry(headerName);
zos.putNextEntry(zipEntry1);
zos.write(("Download Date of the file was : " + mm + "/" + dd + "/" + ccyy).getBytes());
zos.closeEntry();
zos.flush();
zos.putNextEntry(new ZipEntry("test.txt"));
//************** Process SE High Risk File
String sql = "CALL zzzz (?)";
CallableStatement callStmt = con.prepareCall(sql);
callStmt.setString(1," ");
callStmt.execute();
ResultSet rs = callStmt.getResultSet();
int i = 0;
while (rs.next())
{
zos.write((rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5) + " " + rs.getString(6) + " " + rs.getString(7) + " " + rs.getString(8) + "\r" + "\n").getBytes());
zos.flush();
i++;
}
zos.closeEntry();
zos.flush();
rs.close();
callStmt.close();
con.close();
zos.close();
os.close();
}
catch(Exception errException)
{
//
}
%>
Regards,
Cheers prasad