<%@ page language="java" contentType="application/bin"
import="java.io.FileInputStream,java.io.OutputStream,java.io.IOException,java.io.File"%><%@ page import="java.net.URLEncoder"%><%
String exportfilepath = (String) request.getAttribute("exportfilepath");
String exportfilename = (String) request.getAttribute("exportfilename");
request.removeAttribute("exportfilepath");
request.removeAttribute("exportfilename");
if (exportfilepath != null && exportfilename != null) {
response.reset();
response.setContentType("application/bin");
String filenamedownload = exportfilepath;
String filenamedisplay = exportfilename;
filenamedisplay = URLEncoder.encode(filenamedisplay, "UTF-8");
response.setHeader("Content-Disposition",
"attachment;filename=" + filenamedisplay);
OutputStream output = null;
FileInputStream fis = null;
try {
output = response.getOutputStream();
fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while ((i = fis.read(b)) > 0) {
output.write(b, 0, i);
}
output.flush();
}catch(IOException ex){
ex.printStackTrace();
}finally {
if (fis != null) {
fis.close();
fis = null;
}
if (output != null) {
output.close();
output = null;
}
}
// try{
// File thefile=new File(icalendarfilepath);
// if (thefile.exists()){
// thefile.delete();
// }
// }catch(Exception e){
//
// }
}else{
out.print("Sorry, there are some errors on the server and the application could not generate"
+" the ICalendar file successfully. Please contact with the administrator.");
}
%>