Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to save dynamically generated PDF files with proper file name?

843842Sep 19 2008 — edited Sep 20 2008
Hi,

I need to save the pdf file with default name which generated by
dinamically.

this is the code i am trying to save by default
 protected void processRequest (HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException
{
OutputStream bos = response.getOutputStream ();

// this returns pdf byte array
byte  ios[]  = callReport ( reportId_param , fullyQualifiedReportClassName , paramHashMap ) ;

response.setContentType ("application/pdf");

// reportId_param and reportName_param supplied from some where
String docName =  reportId_param + "_" + reportName_param ;

if( fromDate_req != null && toDate_req != null )
 {
                String dateStr = fromDate_req + "_to_" + toDate_req ;
                dateStr = dateStr.replaceAll ( "/" , "_" ) ;
                docName = docName + "_" + dateStr ;
  }

// here docName would be like "RP_COM_COLL_01_Message_Details_03_09_2008_to_03_09_2008"

response.setHeader ("Content-Disposition","inline; filename=" + docName ) ;

bos.write (ios);
bos.flush ();

}
the above code produces pdf in browser when calling this URL
http://localhost:8080/DAD01TN0801027/RWReportServlet

In browser we can save this PDF by using two ways
1. File -> Save As
2. By using Save Icon within the PDF toolBar

both the actions uses the file name "RWReportServlet" as default instead of using docName

Can any one help me please

Regards
Sakthivel.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 18 2008
Added on Sep 19 2008
5 comments
551 views