Reading
file from the server file path and Downloading through struts2 web application
Fix for Unable to download - IE8
HttpServletResponse httpResponse = ServletActionContext.getResponse();
response.setContentType("application/octet-stream");
response.setHeader("Cache-control","public");
response.setHeader("Content-Disposition","inline; filename="+document_name);
ServletOutputStream serveltOutputStream = null;
File file = null;
FileInputStream fis = null;
try {
serveltOutputStream = httpResponse.getOutputStream();
file = new File("server_file_path" + document_name);
fis = new FileInputStream(file);
byte[] byteBuff = new byte[1024];
int read = 0;
while((read = fis.read(byteBuff ))!= -1){
serveltOutputStream.write(byteBuff ,0, read);
}
serveltOutputStream.flush();
} catch (Exception exception) {
e.printStackTrace();
} finally {
try {
serveltOutputStream.close();
log.info("finally Ends....");
} catch (Exception exception1) {
}
}
No comments:
Post a Comment