Chapter 13. Serving SVG Files

In most of the preceding chapters, we have presented a general view of SVG and have tried to be application-agnostic. The techniques you’ve seen can be applied to diagrams destined for print, for conversion of legacy data to a more transportable format, and, of course, for web graphics. In this chapter, we will consider the problem of accessing data in XML format, transforming it to SVG, and then sending it to a client on the Web.

Serving Web Files -- The Task at Hand

We will present a list of airports on a web page, and let the users select one whose weather report they wish to see. The request will be sent to a Java servlet, which will retrieve the information in Weather Observation Markup Format (OMF) and send back a web page containing a graphic presentation of the data. Though SVG is the most compact representation — and this is a book about SVG, after all — some users may not have an SVG plugin for their browsers. Thus, we will offer them a choice of receiving the graphic in SVG or in one of two rasterized formats: PNG (Portable Network Graphics) or JPG. We offer JPG for users with older browsers that don’t support PNG. The web page is shown in Figure 13-1.

This example uses a servlet without explaining the servlet mechanism in any great detail. You can find that information in Java Servlet Programming by Jason Hunter and William Crawford, published by O’Reilly & Associates.

Figure 13-1. Screenshot of web page

The resulting graphic will be a modified ...

Get SVG Essentials 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.