在我的申请中,没有特定投标的文件(pdf)。我需要从这些 pdf 文件创建一个 zip 文件并允许用户下载它。
应用程序是在 JavaEE 中使用 struts 和 mysql 完成的。当用户单击下载按钮时,此操作类被调用。该代码没有给出任何异常,但也没有提示用户下载任何内容。
请帮我找出代码中的问题。
以下是我的动作类的源代码..
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;
}
}