我做了一个上传下载的功能,但是下载的时候用迅雷可以下载,用IE就会报错
错误提示是无法找到Internet站点,请求的站点不可用或无法找到。哪位大虾知道该怎么解决这个问题吗?
小弟拜谢了!

解决方案 »

  1.   

    <%@ page contentType="text/html; charset=UTF-8" language="java" %><%@ page import="org.springframework.context.ApplicationContext" %><%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %><%@ page import="com.yzwb.cctv.dao.BaseDao" %><%@ page import="com.yzwb.cctv.domain.Accessory" %><%@ page import="java.util.List" %><%@ page import="java.net.URLEncoder" %><%@ page import="java.io.*" %><% String id = request.getParameter("id");
    ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(application);
    BaseDao baseDao = (BaseDao)ctx.getBean("baseDao");

    String hql = "from Accessory where id = ?";
    List list = baseDao.find(hql,id);
    Accessory accessory = (Accessory)list.get(0);

    response.addHeader("Content-type","application/vnd.ms-word");
    response.addHeader("Content-Disposition","filename=" + URLEncoder.encode(accessory.getFileName(),"UTF-8"));

    OutputStream os = response.getOutputStream();
    File file = new File(accessory.getStoragePath());

    InputStream is = new FileInputStream(file);


    byte[] bytes = new byte[1024];

    int b = 0;

    while((b = is.read(bytes)) > -1){

    os.write(bytes,0,b);
    }

    is.close();

    os.close();%>这是下载功能
    是一个JSP页面
      

  2.   


    //下载
    String filePath = filedb.getFile_url();
    String filetype = filePath.substring(filePath.lastIndexOf('.'));
    String msg = "";
    if(filePath != null && !"".equals(filePath))
    {
    String path = getServlet().getServletContext().getRealPath("")+filePath;//找到文件
    response.addHeader("Content-Disposition", "attachment; filename="+new String((filename+filetype).getBytes("gb2312"), "ISO8859-1"));
    response.setContentType("application/octet-stream");

    ServletOutputStream output = response.getOutputStream(); 
    InputStream fis = null; 
    byte[] buffer = new byte[1204];
    int byteRead; 
    try 

    fis = new FileInputStream(path); 
    while ((byteRead = fis.read(buffer)) != -1) 

    output.write(buffer, 0, byteRead); 

    output.flush(); 

    catch (Exception e) 
    {
    String simplename = e.getClass().getSimpleName();
    if(!"ClientAbortException".equals(simplename))  // 忽略用户点击下载取消按钮时的警告异常
    {
    response.setContentType("text/html; charset=utf-8"); 
    response.setHeader("Content-disposition", "inline"); 
    output.println(" <HTML> <BODY> <P>"); 
    output.println("文件下载发生错误!"); 
    output.println(" </P> </BODY> </HTML>"); 
    output.close();
        }

    finally
    {
    if (fis != null) 

    fis.close(); 

    }

    }
    else
    {
    msg = "找不到文件,该资料可能未上传";
    }
    response.getWriter().write(msg);
    response.getWriter().flush();
    response.getWriter().close();
    return null;
      

  3.   

      String path = getServlet().getServletContext().getRealPath("")+filePath;//找到文件
                    response.addHeader("Content-Disposition", "attachment; filename="+new String((filename+filetype).getBytes("gb2312"), "ISO8859-1"));
                    response.setContentType("application/octet-stream");
    还有.close写到finally里面
      

  4.   

    好了,问题已经解决了,是下载链接的错,我写了个onclick的JS方法,用了window.open方法,不知道为什么IE不能这样读数据.这次长记性了,以后不这样弄了.
      

  5.   


    //下载
    function downLoad()
    {
    var filePath = $("#uploadPath").val();
    window.location.href="AP06004Action.do?option=downLoad&filePath="+filePath;
    }