Seeing the Results in Excel
To see the SpreadSheetServlet
servlet in action, all you have to do is access the servlet from a Web browser. Obviously, the machine that is accessing the servlet needs to have Microsoft Excel installed so that it can interpret the Excel content when the servlet responds.
The URL you use to access the servlet depends on the context root that you define for the project in your EAR application deployment descriptor (application.xml
). Note the <context root>
element in the code below:
<?xml version="1.0" encoding="UTF-8"?>
<application id="Application_ID" version="1.4"
The URL also depends on the <servlet-mapping>
tag you define in the Web deployment descriptor, web.xml,
as specified by the <url-pattern>
So using the example data above, you'd access the servlet using the address:
The servlet, displayed in Internet Explorer, is shown in Figure 3
|Figure 3. Sample Spreadsheet: The figure shows the Microsoft Excel spreadsheet produced by accessing the SpreadSheetServlet.|
To make sure the Excel spreadsheets being produced by the servlet are truly up-to-date, you can issue an UPDATE
statement using the DB2 command line processor to update the player's statistics.
In this article you've seen how to create simple spreadsheets in a Java servlet for consumption by a Web browser. Such a facility enables your Web site visitors to view current data from your database in a familiar format: a Microsoft Excel spreadsheet. You might use such dynamically-created spreadsheets to inform clients about current inventory, or to provide your accounting department with current database data.
If you've ever tried it, teaching a non-techie how to issue an SQL query can be quite a painful experience. Letting the bean counters in your enterprise do their bean counting using a familiar tool such as Microsoft Excel is a much more efficient approach.
This approach has its limitations, though. You do not have the fine-grained power to create spreadsheets like the ones you can produce using Apache Jakarta POI
. If you need to create spreadsheets where you can manipulate fonts and specific fields, you'll be happier with an architecture that uses Apache POI on your application server. See the article "Learn to Read and Write Microsoft Excel Documents with Jakarta's POI
" for more on the POI project.