hi
i am trying to make a download. The logic that i am using is to send three variables via query string to the servlet, which get them and generate the report and place it in the directory. I then have to make that report download.
My HTML form is
and the javascript code isCode:<form name="reportDownload" action="/DownloadReport" method="GET"> <input type=hidden name=code value=0> <input type=hidden name=logic value=0> <input type=hidden name=file value=0> <TABLE align=center border=0 cellPadding=0 sellSpacing=0 width=95%> <TR> <TD align=left width=80%><FONT face=Verdana size=1> </FONT></TD> <TD align=right><FONT face=Verdana size=1><B>Download:</B></FONT></TD> <TD align=right title="Comma Separated File(CSV)"><FONT face=Verdana size=1><a href='#' onclick="downloadReport('CSV')"><div style="">CSV</a></FONT></TD> <TD align=right title="Adobe Acrobat Reader File"><FONT face=Verdana size=1><a href='#' onclick="downloadReport('PDF')">PDF</a></FONT></TD> <TD align=right title="Excel Format File"><FONT face=Verdana size=1><a href='#' onclick="downloadReport('XLS')">XLS</a></FONT></TD> </TR> </TABLE> </form>
and the final Servlet Code isCode:function downloadReport(fileType){ if (fileType == "CSV"){ document.reportDownload.file.value=1; } document.reportDownload.code.value=<%=subscribeCode%>; document.reportDownload.logic.value=<%=applicationLogic%>; document.reportDownload.submit(); }
Now the problem is that ... [*] ... my form is not being submited to the servlet ...Code:String path = path = getServletConfig().getServletContext().getRealPath(getServletConfig().getServletName()); path = path.substring(0, path.lastIndexOf("\\")); path += "\\subscribers"; ReportInfo report = new ReportInfo(); report.setSubscriberCode(Integer.parseInt(request.getParameter("code"))); report.setReportType(Integer.parseInt(request.getParameter("logic"))); report.setFileType(Integer.parseInt(request.getParameter("file"))); report.setPath(path); boolean status = report.generateReport(); if (status){ byte[] fileByte = null; ServletOutputStream servletOut = response.getOutputStream(); File file = new File (report.getFilePath()); FileInputStream f = new FileInputStream(file); fileByte = new byte[f.available()]; f.read(fileByte); if (report.getFileType() == report.FILETYPE_CSV){ response.setContentType("text/csv"); } response.setContentLength(fileByte.length); servletOut.write(fileByte, 0, fileByte.length); servletOut.flush(); servletOut.close(); f.close(); }... i guess there is some problem in web.xml but i am unable to fix it.
[*] ... 2nd thing ... if i make a call to the servlet manually, it is not downloading the file ... can any one of you figure this out ???Code:<servlet-mapping> <servlet-name>DownloadReport</servlet-name> <url-pattern>/DownloadReport</url-pattern> </servlet-mapping>


... i guess there is some problem in web.xml but i am unable to fix it.
Reply With Quote


Bookmarks