Friends,
After an entire day of research, I have located code that will prompt the user to download a file with a "Save As" dialog box. This can be inserted in a JSP because a JSP is really a servlet (don't let the imports fool you.)
Here it is...
<%@ page contentType="text/html"%>
<%@ page language="java"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="javax.servlet.*"%>
<%
if (request.getParameter("filename").equals("") == false) {
OutputStream o = response.getOutputStream();
String path =request.getParameter("path");
String filename=request.getParameter("filename");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;
filename="+request.getParameter("filename"));
int iRead;
FileInputStream stream = null;
try {
File f = new File(path+filename);
stream = new FileInputStream(f);
int ilength = 0;
while ((iRead = stream.read()) != -1)
{
o.write(iRead);
}
o.flush();
}
finally {
if (stream != null) {
stream.close();
}
}
}
%>