A classe seguinte faz o download do arquivo especificado, no diretorio
especificado. Ela funciona normalmente no Apache/Jserv, mas no meu servidor
com Win Nt/Lotus Domino ele tambem faz o download do arquivo mas qdo tento
executa-lo ele informa que nao eh um aplicativo win32 valido.

Alguem sabe explicar pq?


import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Download extends HttpServlet {

public void doGet(HttpServletRequest req ,HttpServletResponse res) throws
IOException,ServletException {
  doPost(req,res);
}
public void doPost(HttpServletRequest req ,HttpServletResponse res) throws
IOException,ServletException {

  String arquivo   = req.getParameter("arquivo");
  String diretorio = req.getParameter("diretorio");
  String tipo      = req.getParameter("tipo");

  String caminho = "d:/"+ diretorio +"\\" + arquivo;
  File F = new File(caminho);
  if (tipo.equalsIgnoreCase("exe")) {
res.setContentType("application/x-msdownload;name=\"" + arquivo + "\""); }
  if (tipo.equalsIgnoreCase("zip")) {
res.setContentType("application/x-zip-compressed;name=\"" + arquivo +
"\""); }
  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();
  }
}
}



------------------------------ 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] 
-------------------------------------------------------------------------

Responder a