Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Filename attribute for Inline Content-Disposition Meaningless?

 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
response.setHeader("content-disposition", "inline;filename="test.pdf");
I read a PDF file on my server using FileInputStream and output it to the response OutputStream. Everything is fine and the Acrobat Reader would launch to display the file.
However, when I click on the save button, the default file name would be "<my jsp file>.pdf".
Using attachment instead of inline solved this but that is not what I want to achive.
So, is there a way to change the default file name for inline?
Thanks in advance.
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try mapping your servlet in the deployment descriptor, so it can be called with a /test or /theNameYouWant url request.
<servlet-mapping>
<servlet-name>ServletName</servlet-name>
<url-pattern>/pdf/test</url-pattern>
</servlet-mapping>
HTH
[ March 14, 2003: Message edited by: Juanjo Bazan ]
 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Juanjo,
... I don't think u get me.
What I'm trying to know is whether we can set
the default file name programmatically, depending on the type of document.
response.setHeader("content-disposition", "attachment;filename=hello.pdf");
If we are using attachment (above), the default file name would be as the one we set in the "filename" attribute. But this method always prompt us the "open" or "save" dialog box which I think is pretty annoying.
So, I want to use the content-disposition "inline" attribute instead which automatically open the file on the browser.
The reason I need the flexiblity to set the file name is very simple. I have only a JSP page which act as a viewer. With it, I view my invoice, statement, etc.
If it's an invoice, the default file name should be something like invoice<timestamp>.pdf. If it's a statement, then it should be statement<timestamp>.jsp
Hope that's clear.
Thanks for the reply.
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, now I get you.
The "inline;filename='name'" should work, check the quotation marks, in your first post they are not correctly nested.
Another point specified in the rfc2183, is that the browser "SHOULD NOT respect any directory path information that may seem to be present in the filename parameter". Maybe your browser is taking the . as a directory separator, try just with the name ("text") without the extension.
(use the content type header to set pdf as content type)
Apart from that, the Filename Parameter is just a suggestion you do to the user agent, have you tried with different browsers?
 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Juanjo,
Tried enclosing the file name in quotation mark.
I end up getting the open/save prompt as if I'm
using "attachment" rather than "inline". The
file name is correct for this.
Then, I tried taking off the extension and I got
the same result as above. I did set the content
type header to PDF for both.
Lastly, I tried using Mozilla as the browser
instead. Originally, I used IE 5. Same result.
... I think the browser somehow ignore the file
name when we use the "inline" method. Guess
I just have to accept it.

Thanks.
 
Christopher Dixon
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't the most elegant solution, but if I understand your requirements correctly:
  • You want the file to open in the users browser, not prompt for 'save' or 'open'.
  • You the browser to recognize the page's file name as something you set.
  • I've had cross-browser problems with quite a few of the HTTP headers, so you're not alone.
    What if you mapped a servlet url-pattern to the beginning of the directory, say ? The browser only cares about the last segment of the URL, so make it whatever you want, but route based on the mapping. So, if you were creating a list of invoices, you could link to . The showInvoice servlet (or JSP) could either perform business logic and stream the content back, or just be a front end controller.
    If you needed to set this at request processing time (as opposed to at link-creation time, the request before), you could use sendRedirect(), but you would need to either store in session or pass in the request any data that you wanted to keep.
    hth,
    Chris
    [ March 19, 2003: Message edited by: Christopher Dixon ]
    [ March 19, 2003: Message edited by: Christopher Dixon ]
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!