When downloading files with jsp, it is downloading my jsp page.
843835Jun 4 2002 — edited Jul 24 2002Does anybody have an idea why the browser is downloading my jsp file instead of the text file I am trying to download? I need help desparately!
Here is my code:
%@ page language = "java" import="java.sql.*, javax.servlet.*, java.util.*, java.io.*" %>
<html>
<%
response.setContentType ("text/html");
//set the header and also the Name by which user will be prompted to save
String filename = request.getParameter("fileName");
String path = request.getParameter("path");
response.setHeader("Content-Disposition","attachment; filename=" + "temp.TXT");
//Open an input stream to the file and post the file contents thru the servlet output stream to the client
int iRead;
FileInputStream stream = null;
try
{
File f = new File(path+filename);
stream = new FileInputStream(f);
while ((iRead = stream.read()) != -1)
{
out.write(iRead);
} out.flush();
}
finally
{
if (stream != null)
{ stream.close(); }
}
%>
</html>
<!--end of download -->