I have a jsp (itemSearch.jsp) to display all items based on user submission. Once the user submits i am calling java method to submit all parameters as shown below
submitItems = itemManager.getProcessedItems(1, itemID, startPage, endPage, fromDate, toDate);
here in getProcessedItems i am fetching data using JDBC connection
public ArrayList getProcessedItems(1, itemID, startPage, endPage, fromDate, toDate) {
ArrayList p_items=new ArrayList();
Connection connection = null;
String sqlStatement = null;
try {
connection = DBManager.getConnection(DBManager.EPM_DATASOURCE_NAME);
if(set==1) {
sqlStatement = "SELECT I.lineid, I.date,S.STATUS, S.DATETIME, ";
sqlStatement += "S.TOTAL FROM ITEM I, LITEM LI, ITEM_STATUS S ";
sqlStatement += "WHERE I.LINEID=LI.ID AND I.ITEMID=? ";
if (fromDate !=null && toDate!=null){
SimpleDateFormat fd = new SimpleDateFormat("MM/dd/yyyy");
String fromdateString = fd.format(fromDate);
String todateString = fd.format(toDate);
sqlStatement += " AND I.PDATE BETWEEN RANGE_DATE('" + fd.format(fromDate) + "','MM/DD/YYYY') AND RANGE_DATE('" + fd.format(toDate) + "','MM/DD/YYYY')";
}
sqlStatement += "ORDER BY I.PDATE DESC";
}
PreparedStatement ps = connection.prepareStatement(paginationBegin+sqlStatement+paginationEnd);
ps.setInt(1, ID);
ResultSet rs = ps.executeQuery();
while(rs.next()) {
if(items.contains(new Integer(rs.getInt("itemid")))==false) {
items.add(new Integer(rs.getInt("itemid")));
ReportItem ri = new ReportItem();
ri.setLineItemID(rs.getInt("lineid"));
ri.setTransmitted(rs.getTimestamp("idate"));
ri.setStatus(rs.getString("status"));
ri.setStatusDateTime(rs.getTimestamp("s_datetime"));
p_items.add(ri);
}
}
rs.close();
ps.close();
} catch (SQLException e) {
log("ERROR");
} catch (NamingException e) {
log("ERROR");
} finally {
DBManager.closeConnection(connection);
}
return p_items;
}
This properly displays data in itemSearch.jsp but now i want to add CSV file (hyperlink in jsp) which contains displayed data in the file for downloading.
i.e
<div align="right" class="TableRows" style="padding-right:10px"><a href="" class="TableRowLinks">CSV File</a></div>
Questions 1. How to generate CSV file from queried result ? 2. How to give link for the same in jsp file?