Chapter 13. Sending Non-HTML Content

Introduction

Most web sites offer a smorgasbord of media types to their users. Typical web content these days includes Portable Document Format (PDF) files, word-processing documents, audio files, movies, and Extensible Markup Language (XML). In some cases, these alternative file types are stored in databases as binary data , or streams of unencoded bytes. Web developers cannot always provide their users with straightforward hyperlinks to these files for downloading. The user chooses a link or enters a URL in the browser’s location field, and a servlet or some other web component downloads the binary data to the client. The client in most cases saves the data as a file, for use later in document viewers and other applications.

The following recipes describe how to initiate this download method. In a typical scenario, the servlet sets up a download whereby the browser prompts the user with a “Save As” dialog allowing him to save the files on his own filesystem. These strategies, however, do not guarantee 100-percent consistent behavior among web browsers. Some browsers allow the user to precisely configure how he wants to handle handle certain file types (such as a PDF document). For example, Opera 5 gives the user all kinds of options for dealing with downloads, such as opening up an external helper application, displaying a file using a plug-in, or immediately downloading a file to a specified folder without first opening up a “Save As” window. ...

Get Java Servlet & JSP Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.