tags:

views:

81

answers:

1

Hi, How can I produce a URL which somebody could open and that would immediately download a file e.g. pdf?

I have been using ice:outputResource but that requires the user clicks on a link. Is it possible to do this in JSF?

Thanks, Dwayne

+2  A: 

You want to download a PDF file immediately when one opens a page? Use Javascript to fire the request on the PDF file during page load.

<script>
    window.onload = function() {
        window.location = 'http://example.com/context/path/to/file.pdf';
    }
</script>

Update: your question is actually ambiguous. From other point of view, are you asking how to return a PDF file on a GET request? If so: if it's a static PDF file, then just put the PDF somewhere in the webcontent and link to it. Or if it's to be dynamically generated or served from a database or local disk file system outside the webapp, then create a servlet which does the job. Example here.

BalusC