我正在使用Wicket(不知道它是否重要),但我正在使用工作簿为用户下载创建一个Excel文件。但我不确定究竟该如何做到这一点。我想要发生的是用户点击按钮,创建一个日志,并提示用户打开(并保存到临时文件)或保存到他们的计算机。然后将文件从服务器端删除,或者将其存储在用户会话中并在会话结束时删除。如何从Web应用程序下载Excel文件?
有人能指出我正确的方向吗?如果我能有未保存在会话中的所有文件,那将会创造和拥有它只是它使用FileOutputStream中以某种方式发送到客户端..
这里是我当前的代码:
private void excelCreator()
{
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet(WorkbookUtil.createSafeSheetName("SSA User ID " + currentSSAIDSelection2.getSsaUserId()));
Iterator<AuditLogEntry> auditLogEntrys = logList.iterator();
int i = 0;
while (auditLogEntrys.hasNext())
{
final AuditLogEntry auditLogEntry = auditLogEntrys.next();
Row row = sheet.createRow(i);
row.createCell(0).setCellValue(auditLogEntry.getTimeStamp());
row.createCell(1).setCellValue(auditLogEntry.getSourceName());
row.createCell(2).setCellValue(auditLogEntry.getCategory());
row.createCell(3).setCellValue(auditLogEntry.getSsaAdmin());
row.createCell(4).setCellValue(auditLogEntry.getAction());
i++;
}
try
{
FileOutputStream output = new FileOutputStream("ssaUserIDAccess.xls");
workbook.write(output);
output.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
没关系,我发现这个链接 http://stackoverflow.com/questions/7646270/how-to-use-wickets-downloadlink-with-a-file-generated-on-the-fly – eaglei22