Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
254
Chapter 11 The JSP page Directive: Structuring Generated Servlets
Generating Excel Spreadsheets
You can create simple Microsoft Excel spreadsheets by specifying
applica
tion/vnd.ms excel
as the content type and then formatting the spread
sheet entries in one of two ways.
One way to format the content is to put rows on separate lines of the docu
ment and to use tabs between each of the columns. Listing 11.3 shows a sim
ple example, and Figures 11 5 and 11 6 show the results of loading the page
in Netscape on a system with Excel installed. Of course, in a real application,
the entries would probably be generated dynamically, perhaps by a JSP
expression or scriptlet that refers to database values that were accessed with
JDBC (see Chapter 18).
Listing 11.3 Excel.jsp
<%@ page contentType="application/vnd.ms excel" %>
<% Note that there are tabs, not spaces, between columns. %>
1997
1998
1999
2000
2001 (Anticipated)
12.3
13.4
14.5
15.6
16.7
Figure 11 5 With the default browser settings, Netscape prompts you before allowing
Excel content.
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved