Issue
I have a servlet code written as shown below,where I am passing the parameters through map function and I have to download the report in PDF format,where while downloading i have to add to my request.getparameter("param2") to request.getparameter("param1") with formatting date as MMddyyyy because it doesn't accept "/" while downloading the file.
Please try to help me with this query,Thank's in advance.
SimpleDateFormat dateFormat2 = new SimpleDateFormat("MM/dd/yyyy");
Map<String, Object> map = new HashMap<String, Object>();
map.put("Course_ID", request.getParameter("param1"));
map.put("StartDate", dateFormat2.parse(request.getParameter("param2")));
map.put("EndDate", dateFormat2.parse(request.getParameter("param3")));
JasperReport jr = JasperCompileManager.compileReport(jrxmlFileName);
JasperPrint jp = JasperFillManager.fillReport(jr, map, conn);
JasperExportManager.exportReportToPdfFile(jp,
"D:/ForReports/Downloads/" + request.getParameter("param1") +".pdf");
System.out.println("Done exporting pdf format to view");
And in html parameters will be getting passed as shown,
<div class=" col-sm-3" class="form-group">
<br>
<p align="center" ><a class="btn icon-btn btn-info" ng-href="JasperServlet2?param1={{modelcourse}}¶m2={{formatDate(startdate) |date:'MM/dd/yyyy'}}¶m3={{formatDate(enddate) |date:'MM/dd/yyyy'}}" target="_blank"><span class="glyphicon btn-glyphicon glyphicon-print img-circle text-success"></span> Click Here To View report</a></p>
</div>
Solution
Hope this code may help :-
String date=request.getParameter("param1");
date=date.replaceAll("/", "");
JasperExportManager.exportReportToPdfFile(jp,
"D:/ForReports/Downloads/" + date +".pdf");
while other code will remain same.
Answered By - Naman jain