I would like to do generate an excel file from the database query results(which are shown in an html), and display those in an downloadable excel sheet on the same page.All this needs to be done using jsf and javabeans(no jsp). The basically i would like to do the java ee equivalent of the following:
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Export_data.xls");
$db_link = db_connect();
$result = odbc_exec($db_link, $query);
?>
<div id="content">
<table width="900px">
<tr>
<th width="10%" align="left"><b>column1</b></th>
<th width="25%" align="left"><b>column2</b></th>
</tr>
<?php
while(odbc_fetch_row($result)){
$col1 = odbc_result($result, 'column1');
$col2 = substr(odbc_result($result, 'column2'),0,30);
echo ('<tr>');
echo ('<td>' . $col1 . '</td>');
echo ('<td>' . $col2 . '</td>');
echo ('</tr>');
}
?>
</table>
</div>
<?php
edit: i want to both generate an excel from an html markup on the page, and display a downloadable version on the same page, without using any external plugin/apis.just like shown in the php. So it is not a duplicate of the other post, which doesnt generate excel from the the markup, and doesnt display it on the same page either.