This is sample code...
Hope this will help u..
<br><br>
File : dispexcel.jsp<br>
<br>
<html>
<%
String convert = request.getParameter("go") ;
if(convert != null && convert.toUpperCase().equals("Y")){
response.setContentType("application/vnd.ms-excel");
}
%>
<table>
<tr>
<td>Name</td>
<td>Phone</td>
</tr>
<tr>
<td>Yogendra</td>
<td>513 674 7375</td>
</tr>
<tr>
<td>
<%
if(convert == null | | convert.toUpperCase().equals("N")){
%>
<form name=myform target="NEW" action=dispexcel.jsp >
<input type=submit value="convert to excel">
<input type=hidden value="Y" name=go>
<%
}
%>
</td>
</tr>
</form>
</table>
</html>