views:

23

answers:

1

Hi folks,

My application is in JSP/Struts and running on WebSphere. I don't have access to the server /really/ so I'm trying to do all this from within the app itself (Struts actions & config, JSP, etc).

I have a page that displays links for PDF documents that the user might want to look at. When they click on the link, it is forwarded to the 'document view' STRUTS action which performs the work to retrieve the PDF from the back-end system and then displays the PDF in the browser window. This all works fine.

The users have asked to have the file name of the document be customized for each document when they go to File->Save As... but right now the browser wants to try to name the document after the name of my Struts action. Example: "documentView.pdf"

I have the filename I want to use forwarded to the STRUTS action and I tried using the "Content-Disposition" header to set this, but haven't been able to get it to work. Actually it works great if I use "attachment; filename="myfilename" " but then it FORCES the "Save As..." dialog straight away, which I don't want either.

I want to be able to look at the PDF inline in the browser window and save it with a custom filename if I so choose.

I have read that this might be possible to do with URL rewriting but I'm having trouble sorting out how this technique might work.

Any ideas will be greatly appreciated.

+2  A: 

Change the "attachment" part of the Content-Disposition to "inline".

Browser support for Content-Disposition is flaky.

Before it was supported, you used to be able to get the browser to do the right thing by putting a superfluous key/value at the end of the URL. Like:

http://example.com/getPDF?id=123213&filename=mydoc.pdf

Some browsers picked up the last bit of the URL as the filename. Not sure if that still works.

Lou Franco
Thanks for your suggestion.I see now I forgot to mention this in the original post but I had already tried that will no success. It seems your statement re flaky browser support is spot on and the browsers I need it to work on (ie6 mainly - boo!) don't support this 'inline;' functionality.
Joel
FTR this works fine in Firefox, but not in IE6...
Joel
I found the same as you - works in FF but not IE6. I will potentially be coming back to this someday.
Joel