• Post Reply Bookmark Topic Watch Topic
  • New Topic

renaming pdf file via servlet  RSS feed

 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i have a servlet which downloads PDF files. Currently the pdf filename defaults to the servlets name, how do i change its name to something else in the servlet so users dont have to use the "save as" option to manually rename the file.

thanks in advance.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set the Content-Disposition response header.
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply. i tried the below :



but the pdf still displays the servlet name. any other suggestions ??

thanks again.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What other values for the disposition have you tried? "inline" isn't the only choice.
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have tried "attachment" as well. Are there any others ??
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the content type?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nikil shar wrote:thanks for the reply. i tried the below :



but the pdf still displays the servlet name. any other suggestions ??

thanks again.


That should have worked.
Are you sure the new class got loaded in your container?

Can you post the code to your servlet?
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wonder if theres any browser restrictions ?? anyway my servlet code is pretty big but heres the bit which i think is relevant and should work, please correct me if wrong :

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're targeting IE (don't know if it's all versions) there's a weird thing about the content length, but I forget what it is.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it on various browsers?
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have tried IE V6, V7 and FireFox V3.6 but my target is to get it working on IE V6.

ta.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check to make sure the response headers are coming across the wire correctly (like with Firebug/etc.)?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nikil shar wrote:have tried IE V6, V7 and FireFox V3.6 but my target is to get it working on IE V6.

ta.

Don't make us pull teeth. Did it work in any of those browsers?
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
haha sorry forgot to mention it didnt work in any of the browsers. must be specific to the browsers i am using since after googling for a bit most of the solutions suggest it should work for "attachments" option. I am more interested in "inline" option though.
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Did you check to make sure the response headers are coming across the wire correctly (like with Firebug/etc.)?


hi David,
i checked in FireFox to see the "pageInfo" had the correct information in it. Is that what you meant ??

ta.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikil,
Post all the code from that method.
Not just where you're setting the headers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!