开发者

rewrite URL to affect "save as" filename

开发者 https://www.devze.com 2023-01-12 21:54 出处:网络
My application is in JSP/Struts and running on WebSphere. I don\'t have acces开发者_JAVA百科s to the server /really/ so I\'m trying to do all this from within the app itself (Struts actions & conf

My application is in JSP/Struts and running on WebSphere. I don't have acces开发者_JAVA百科s 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消