JSP That Brings Up an Excel Spreadsheet

Here is a JSP that causes an Excel spreadsheet to be displayed in the browser. Of course, you can include Java code that dynamically fills in the rows of the spreadsheet, the data most likely coming from a database.

<%@ page import="java.sql.*, java.util.*"%>
   <%
   response.setContentType("application/vnd.ms-excel");
   response.setHeader("Content-disposition", "attachment; filename=    Contacts.xls" );
   response.setHeader("Cache-Control","max-age=0");
   %>
 <table cellpadding="0" cellspacing="0" border="1">
   <tr style="font-weight: bold">
   <td>Expiration Date</td>
   <td>BR</td>
   <td>FC</td>
   <td>Lead Type</td>
   <td>Company Name </td>
   <td>Prefix</td>
   <td>First Name</td>
   <td>Initial</td>
   <td>Last Name</td>
   <td>Title</td>
   <td>Address</td>
   <td>City</td>
   <td>State</td>
   <td>Zip</td>
   <td>Phone</td>
   <td>Email Address</td>
   <td>Gender</td>
   <td>Age Group</td>
   <td>Own Home</td>
   <td>Marital Status</td>
   <td>Income</td>
   <td>Number of Employees</td>
   <td>Sales Volume</td>
   </tr>
 </table>