I want to invoke my jsp page from my index.html.This is html code.
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<form action="DownloadFile.jsp">
<body>
<div>Click here Download File from Server...</div>
<input type="submit" name="downloadButton" value="Download..." />
</body>
</form>
</html>
JSP PAGE:
<%
String filename = "Sample1.zip";
String filepath = "e:\\temp\\";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename);
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
%>
But When i pressing Download Button, it just shows the jsp file content as html.it does not start downloading the file anyway. What is the problem here...
and also i cann't download .docx and .jpg files correctly.It says file may be corrupted...
Please Guide me to get out of this both issues...
Is there a common way to download all types of files in jsp?