Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

When downloading files with jsp, it is downloading my jsp page.

843835Jun 4 2002 — edited Jul 24 2002
Does 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 -->
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2002
Added on Jun 4 2002
14 comments
1,269 views