0

I am using JSF 1.1. On click of a button I need to download a file from webapp/pdf directory. How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

2

Just link to its URL directly. Both the server and the browser will do the necessary magic.

The desired HTML output should look like this:

<a href="/yourcontext/pdf/filename.pdf">
    Download PDF
<a>

The JSF 1.1 on JSP way to generate this HTML is:

<h:outputLink value="${pageContext.request.contextPath}/pdf/filename.pdf">
    <h:outputText value="Download PDF" />
</h:outputLink>

Or, when you're using JSF 1.1 on Facelets:

<h:outputLink value="#{request.contextPath}/pdf/filename.pdf">
    Download PDF
</h:outputLink>

If necessary, throw in some CSS to make it look like a "button".

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks Balus, this gives 404 error I used like its working but the Download PDF is not visible but its there. How it will work on button click – Jagannath Sabat Jun 02 '15 at 11:31