<%@ page import="java.io.*" %>
<%
// example:
// <a href="download.JSP?path=img/&name=test.gif">download image</a>
String root = getServletContext().getRealPath("/");
String path = request.getParameter("path");
String name = request.getParameter("name");
System.out.println(root + path + name);
response.setContentType("unknown");
response.addHeader("Content-Disposition", "attachment;filename=\"" + name + "\"");
try
{
out.clear();
out = pageContext.pushBody();
OutputStream os = response.getOutputStream();
FileInputStream fis = new java.io.FileInputStream(root + path + name);
byte[] b = new byte[1024];
int i = 0;
while ( (i = fis.read(b)) > 0 )
{
os.write(b, 0, i);
}
fis.close();
os.flush();
os.close();
}
catch ( Exception e )
{
}
%>
<%
// example:
// <a href="download.JSP?path=img/&name=test.gif">download image</a>
String root = getServletContext().getRealPath("/");
String path = request.getParameter("path");
String name = request.getParameter("name");
System.out.println(root + path + name);
response.setContentType("unknown");
response.addHeader("Content-Disposition", "attachment;filename=\"" + name + "\"");
try
{
out.clear();
out = pageContext.pushBody();
OutputStream os = response.getOutputStream();
FileInputStream fis = new java.io.FileInputStream(root + path + name);
byte[] b = new byte[1024];
int i = 0;
while ( (i = fis.read(b)) > 0 )
{
os.write(b, 0, i);
}
fis.close();
os.flush();
os.close();
}
catch ( Exception e )
{
}
%>