7.5. Using Servlets to Generate GIF Images

Although servlets often generate HTML output, they certainly don't always do so. For example, Section 11.2 (The contentType Attribute) shows a JSP page (which gets translated into a servlet) that builds Excel spreadsheets and returns them to the client. Here, I'll show you how to generate GIF images.

First, let me summarize the two main steps servlets have to perform in order to build multimedia content. First, they have to set the Content-Type response header by using the setContentType method of HttpServletResponse. Second, they have to send the output in the appropriate format. This format varies among document types, of course, but in most cases you use send binary data, not strings as with HTML ...

Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.