Thursday, September 6, 2012
Excel export With "save as Excel" Prompt from JSP
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=\"report.xls\"");
%>
<sql:query var="result" dataSource="jdbcJNDI">
select * FROM
X
WHERE
X.y = ? and X.z = ?
<sql:param value="${param.from}"/>
<sql:param value="${param.to}"/>
</sql:query>
<table border="1">
<!-- column headers -->
<tr>
<c:forEach var="columnName" items="${result.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
</tr>
<!-- column data -->
<c:forEach var="row" items="${result.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment