Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Content-Disposition header filename in iText java

I am getting the userid from here

 String struserid  = tempdb.getuserid();

This is how I am setting content disposition header.

        response.setHeader("Content-Disposition", "attachment; filename=sample.pdf");

This will prompt to download an attachment with filename as 'sample.pdf'. But I need the filename like '123456_sample.pdf'

Note: 123456 is the value that I got from db and it is stored as string struserid


1 Answers

Just concatenate the strings:

response.setHeader("Content-Disposition", "attachment; filename=" + struserid + "_sample.pdf");
like image 189
Chris Haas Avatar answered Mar 17 '26 21:03

Chris Haas