Force Download Servlet v. 1.2

Here is a useful component for delivering multimedia file downloads to your users. Typically, browsers will attempt to play or stream such files when direct links are clicked. With this servlet, provide a link to a multimedia file and a dialogue box will provide users the choice of saving the file or opening it. Technically this servlet will set content type to the downloaded media files to application/octet-stream (or any other type you can provide as an initial parameter for this servlet) regardless of the mime type provided by the server. How to use it:

1) download forcedownloadPackage.jar and save it in WEB-INF/lib

2) describe ForceDownload servlet in web.xml file. You can add also an optional initial parameter mime. Default value is application/octet-stream  


    <servlet>
     <servlet-name>ForceDownloadServlet</servlet-name>
     <servlet-class>com.jsos.download.ForceDownloadServlet</servlet-class>
     <init-param>
      <param-name>mime</param-name>
      <param-value>application/octet-stream</param-value>
     </init-param>
    </servlet>

3) define a mapping. E.g.:
 


    <servlet-mapping>
     <servlet-name>ForceDownloadServlet</servlet-name>
     <url-pattern>*.mp3</url-pattern>
    </servlet-mapping>

and now for any mp3 file requested from your site:
 


http://your_host/data/some_file.mp3

this servlet will set mime type to application/octet-stream (force file downloading rather than playing).

For JSP see also Download taglib in Coldtags suite

For downloading:

servlet: forcedownloadPackage.jar  
 

 © Coldbeans    Comments?
 

See also JSOS - the largest collection of servlets and filters.


     

Also in Coldtags: