|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
General Java Java Developer's Guide to Using Spreadsheets on the Web
Java Developer's Guide to Using Spreadsheets on the Web
By: Mark Spencer
Apr. 1, 2000 12:00 AM
They're one of the most commonly used computing tools in business today, regardless of a company's revenues or number of employees. Wall Street money mavens use them, and so does your hometown accountant...spreadsheets. Did you ever tweak spreadsheet formulas to play "what-if" games with your stock portfolio? Have you ever received an e-mail with a spreadsheet attachment full of sales figures or forecasts? And by the way, how did your friend send you the results of this week's fantasy football league? Thanks largely to the widespread distribution of Microsoft Office and Microsoft Excel, the spreadsheet is perhaps the top data analysis and reporting tool in the industry. Distinguished by a rows-and-columns interface that even the casual computer user can understand, spreadsheets provide a wide range of functionality that many types of businesses can leverage. They present data in an understandable format, provide intuitive interfaces for data collection, deliver fast calculations, and report and analyze data from databases and other sources. Given their popularity and effectiveness, it's logical to use spreadsheets for data analysis when building Java-based e-business and B2B applications. As you'll see later, they're especially effective when used to build servlets and Java Server Pages. In this capacity spreadsheets can play the vital role of constructing business logic and rules for data analysis in the middle of Web-centric, three-tier architectures (see Figure 1).
Why Use Spreadsheets?
State Street Corporation in Boston, for example, makes extensive use of spreadsheets in an application called NAVAlert. State Street's fund managers establish their own business rules within the application's spreadsheets to notify them when fund prices meet certain levels. When the fund managers need to alter the rules to account for changing market conditions, no one on State Street's development team needs to get involved. Instead the fund managers change the rules in the spreadsheets by themselves. The same scenario is entirely possible using Java spreadsheets on the server as templates for incoming data. When the rules of a business change, a developer or end user can simply provide a new spreadsheet template that contains the new business logic, thereby reducing application development time and costs. Another use of spreadsheets within Java development is to leverage their inherent analytical capabilities. Especially in applications that call for specialized computations, the formulas built into spreadsheets, together with their engineering, statistical and financial functions, can save developers substantial time. And because most spreadsheets also provide a charting component for additional data display options, developers no longer need to worry about providing that functionality from scratch either.
Where Spreadsheets Are Used
Some current examples of where and how businesses are using spreadsheets in multitier architectures include:
When to Use Spreadsheets
A developer can determine whether or not an application's requirements truly constitute a large amount of data. For an application with simple calculations involving a small number of variables, a spreadsheet calculation engine obviously might not be necessary. But for volumes of data covering a long time period and typically collected from a database, a spreadsheet provides an extremely manageable paradigm for calculations and a useful grid interface for presenting and manipulating data. Using spreadsheets for calculations is especially effective in server-side applications. For example, data from several sources might be poured into a spreadsheet for analysis before being passed to clients or stored in yet another database. Numerous financial services companies use spreadsheets on the back end for just this purpose. In a nutshell, one of the strongest facets of spreadsheets is that they can increase efficiency by performing calculations and data analysis on the server. This is especially true in distributed, three-tier computing environments that rely on Java technology. Options for Using Spreadsheets in Java Development
Since familiarity with using Excel is widespread, it makes sense to leverage the Excel application, the Excel file format and the expertise of end users whenever possible. But Excel has limitations for Java developers who deploy applications widely on the Web outside firewalls. These limitations include a dependence on Windows, a limited API, the inability to be embedded and deployed within an application and the inability to leverage advances in Web, application and database servers. These issues noted, developers can choose one of the following options:
With these abilities in mind, the examples in the remainder of this article are intended to show how to build Java spreadsheet solutions in environments with Formula One with and without Windows and Excel being present.
Leveraging Excel on the Desktop With Server-Side Java and MIME Types
These examples use an Oracle8i database with 12 months of sales figures for a fictitious company. It's assumed a Web page has been built with a form allowing users to select the month of sales figures they'd like to receive in an Excel file. The form has a drop-down box with its NAME attribute set as "month" and its action pointing to the servlet, ExcelServlet. The ExcelServlet reads in a prebuilt Excel file to initialize the in-memory spreadsheet report_template.xls, see Figure 3 connects to the database to populate selected spreadsheet cells from data returned from a JDBC query, and then writes the spreadsheet to the servlet output stream with an appropriate MIME type. This MIME type, "application/vnd.ms-excel", forces the browser to load the Excel plug-in and display the spreadsheet. The database-related procedures have been modularized in the dbManipulatations.java class (see Listing 1) and the servlet specific code is shown in ExcelServlet.java (see Listing 2). The class dbManipulations.java connects to the database via JDBC and populates rows in the report_template.xls spreadsheet based on the user input from the Web page. The ExcelServlet.java class provides the servlet "plumbing" to write the Excel data to the browser after the model has been dynamically created. Invoking the ExcelServlet from a browser with month and reportTemplate parameters should show a Web page like the one depicted in Figure 4. This demonstrates one way developers can leverage spreadsheets in the middle tier and Excel on clients' desktops, even if the application's architecture doesn't include a Windows-based server.
Leveraging Excel on the Desktop with Server-Side Java and JavaMail
The addition of JavaMail notwithstanding, this implementation is similar to the prior example and is illustrated in Figure 5. First, it's assumed there's a Web page with a form that asks for an e-mail address where the report will be sent and a month of sales figures for Formula One to generate. The page and resulting spreadsheet that is sent by e-mail could look like those in Figures 6 and 7. (Note: This demo would also work by accessing the servlet with a name=value pair that includes the parameters &to=name@domain.com&month=SelectedMonth.) Embedded into a servlet, Formula One uses a spreadsheet created in Excel as a template for this example we'll use the template in Figure 3 from the prior demo - then connects to the database and populates specified cells with the data values returned from the JDBC call. From there, it performs a recalculation of the new data, writes the spreadsheet as an Excel file and e-mails it to the submitted e-mail account using the standard JavaMail API. The code required to perform these actions can be found in Listing 3, WebMail.java. As with the prior example, the dbManipulations.java class of Listing 1 includes the modularized database code and will be needed to compile this servlet.
No Excel? How to Deliver Spreadsheets to Thin and Non-Windows Clients
This example is similar to the others. The same spreadsheet will be used on the server to calculate sales figures for a selected month. However, in this case the finished spreadsheet will be written out as an HTML table through a JSP that utilizes Formula One's HTMLWriter method. The requesting HTML page references our JSP page, report.jsp, rather than the ExcelServlet and passes the requested month as a parameter (see Figure 8). The code for report.jsp is in Listing 4. This architecture allows users to leverage a spreadsheet's calculations on a server regardless of the operating system or bandwidth situation, as shown in Figure 9. Formula One also offers the ability to deliver spreadsheets and charts as static GIF, JPG or PNG images for thin-client environments where users simply need to view data. For more information on Formula One visit their Web site at www.tidestone.com.
Summary
Add Java's server-side strengths and it becomes clear that a spreadsheet can be extremely useful behind the scenes of an application, particularly in the middle layer of three-tier architectures when a large amount of data needs to be computed and analyzed. Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||