Have Download File functionality in JHeadstart display the proper file name in the "Save File As" dialog


Creating ‘download file’ functionality in our ADF Web Applications is pretty easy, especially when using JHeadstart. Using a few declarative settings, we can generate the download capability in no time at all:

There is one just little thing left to be desired: the download dialog for some reason does not know the correct name of the file we are downloading:....

Here we are downloading AdfMatrixDemo.zip but the browser calls it ordDeliverMedia.zip, a generic name used for all files we download.

Fortunately, this can be remedied very easily. (this happens to have been my very first job with Java technology, back in 1999). All we have to do is set a header in the Response object in which we return the file:


This informs the browser – or at least the ones that are listening, as some browsers I believe ignore this piece of information – of the correct file name. 

You may – and probably should -wonder where you can inject this line of code – and where to get the filename from. It turns out to be pretty simple for JHeadstart environments.

All downloads are handled by the OrdPlayMediaServlet that is configured in the web.xml file. If we register our own extension of this Servlet, and set the required response header in it, we are in business. The steps:

  1. create class AMISOrdPlayMediaServlet, extending oracle.jheadstart.ord.html.OrdPlayMediaServlet; let’s keep it simple and just copy all code from OrdPlayMediaServlet to AMISOrdPlayMediaServlet.
  2. locate the renderContent() method; add a single line of code, following the assignment of ordObj:
  3. register the AMISOrdPlayMediaServlet in web.xml

And let’s run the application:

And there we have it: the browser uses the correct filename!

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director and Oracle Developer Champion. Solution architect and developer on diverse areas including SQL, JavaScript, Kubernetes & Docker, Machine Learning, Java, SOA and microservices, events in various shapes and forms and many other things. Author of the Oracle Press book Oracle SOA Suite 12c Handbook. Frequent presenter on user groups and community events and conferences such as JavaOne, Oracle Code, CodeOne, NLJUG JFall and Oracle OpenWorld.

1 Comment

  1. Hi,

    I have an application in JDeveloper (10.1.3) with an af:golink whcih has the same behaviour you show above. Can you tell me how/where I can ‘inject the line of code’ so that the filename will appear instead of OrdDeliverMedia, as you describe above (I have the filename on the form, but not as part of the link – The form displays an image and the filename of the image is a label).