In my application there are no of documents(pdf) for a particular tender. I need to create a zip file from those pdf files and allow user to download it.
Application is done in JavaEE with struts and mysql. when user clicks the download button this action class gets called. The code does not give any exceptions but it does not prompt user to download anything either.
Please help me find what is wrong in the code.
Following is the source code of my action class..
public class ActDownloadDocZip extends Action {
static Logger logger = Logger.getLogger(ActDownloadDocZip.class);
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String realPath = getServlet().getServletContext().getRealPath(
"/WEB-INF/log4jConfiguration.xml");
DOMConfigurator.configure(realPath);
logger.info("In ActDownloadDocZip....");
ActionForward forward = null;
HttpSession session = request.getSession();
// get a db connection
Connection conn = null;
String[][] nameFile = null;
String tenderNo = "";
try {
conn = ProxoolConnection.getProxoolConnectionSLT();
tenderNo = request.getParameter("tenderNo");
// File fileex=new File("xxx.zip");
FileOutputStream zipFile = new FileOutputStream(new File("xxx.zip"));
ZipOutputStream output = new ZipOutputStream(zipFile);
// call getPdfFiles method here
ILoadTenders ld = new LoadTenders();
nameFile = ld.getPdfFileListToTender(conn, tenderNo);//this method brings back the relevant pdf file names and paths((pdfname1,pdfpath1),(pdfname2,pdfpath2))
for (int i = 0; i < nameFile.length; i++) {
ZipEntry zipEntry = new ZipEntry(nameFile[i][0].trim());
output.putNextEntry(zipEntry);
FileInputStream pdfFile = new FileInputStream(new File(
nameFile[i][1].trim()));
IOUtils.copy(pdfFile, output);
pdfFile.close();
output.closeEntry();
}
output.finish();
output.close();
} catch (SQLException e) {
System.out.println("actDownloadDocZip " + e);
logger.fatal(e.getMessage());
} catch (Exception e) {
System.out.println("actDownloadDocZip1 " + e);
logger.fatal(e.getMessage());
} finally {
if (conn != null) {
ProxoolConnection.closeProxoolConnectionSLT(conn);
}
}
forward = mapping.findForward("publicdashboard");
return forward;
}
}