Eu estou tentando construir um servlet que faca o download de um arquivo,
mas o servlet a seguir exibe a tela que pergunta se eu desejo abrir ou
salvar a *pagina* atual. Se eu escolher abrir ele entao exibe a tela para
abrir ou salvar o arquivo (que eh o que eu desejo).
Alguem poderia me dizer o que tem de errado nele?
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class SalvaArquivo extends HttpServlet {
>
> public void doPost(HttpServletRequest req ,HttpServletResponse res) throws
> IOException,ServletException {
>
> String arquivo = req.getParameter("arquivo");
> String diretorio = req.getParameter("diretorio");
>
> String caminho = "d:/"+ "intranet/" + diretorio +"\\" + arquivo;
> File F = new File(caminho);
> res.setContentType("application/x-msdownload");
> res.setHeader("Content-Disposition", "attachment;filename=\"" + arquivo
> +"\"");
>
> ServletOutputStream out = res.getOutputStream();
> InputStream in = null;
> try {
> in = new BufferedInputStream(new FileInputStream(F));
> int ch;
> while ((ch = in.read()) !=-1){
> out.print((char)ch);
> }
> }
> catch(Exception e){
> System.out.println(e.toString());
> }
>
> finally {
> if (in != null) in.close();
> out.close();
> }
> System.out.println(caminho);
> System.out.println(arquivo);
> }
> }
>
------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------