Galera estou com um codigo que me da a opcao de download.
O codigo esta blz, mas esta ocorrendo este erro direto description The requested resource (/file/envio) is not available.
Estou usando tomcat 6, netbeans 6
Trecho do codigo(envio.html):
..
<center><h1> Arquivo para teste - PDF </h1></center>
<hr><hr>
<a href="envio?filename=arquivo1.pdf&pathname=c:/tmp/">
Download: Arquivo
</a>
..
Java. (processa.java)
..
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class processa extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String filename = request.getParameter("filename");
String pathname = request.getParameter("pathname");
ServletOutputStream out = response.getOutputStream();
File file = new File(pathname + filename);
FileInputStream in = new FileInputStream(file);
String mime = "application/octet-stream";
String testname = filename.toUpperCase();
if(testname.endsWith(".JPEG"))
mime = "image/jpeg";
else if(testname.endsWith(".JPG"))
mime = "image/jpg";
else if(testname.endsWith(".PDF"))
mime = "application/pdf";
else if(testname.endsWith(".ZIP"))
mime = "application/zip";
else if(testname.endsWith(".MPG"))
mime = "video/mpeg";
else if(testname.endsWith(".txt"))
mime = "application/txt";
else if(testname.endsWith(".GIF"))
mime = "image/gif";
response.setContentType(mime);
response.addHeader("content-disposition",
"attachment; filename=" + filename);
response.setContentLength((int)file.length());
int octet;
while ((octet = in.read()) != -1)
out.write(octet);
in.close();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
..
Alguem sabe o que pode ser?
