<a href="uploads/01需求分析.doc" target="_blank">点击下载</a>当点“点击下载”提示找不到这个文件,就是因为中文文件名的问题,改成英文文件名就可以了,
请问如果不改成英文文件名的情况下,如何能正常下载呢

解决方案 »

  1.   

    楼主用的是tomcat吗,还是其它,修改tomcat的配置文件,改下编码!!!
      

  2.   

    是tomcat,能不能不改TOMCAT呀,其它方法最好
      

  3.   

    <%@page language="java" contentType="application/x-msdownload" import="java.io.*,java.net.*" pageEncoding="gbk"%><% 
      response.reset();//可以加也可以不加  response.setContentType("application/x-download");//设置为下载application/x-download  // /../../退WEB-INF/classes两级到应用的根目录下去,注意Tomcat与WebLogic下面这一句得到的路径不同,WebLogic中路径最后没有/  ServletContext context = session.getServletContext();  String realContextPath = context.getRealPath("")+"\\plan\\计划数据模板.xls";  String filenamedisplay = "计划数据模板.xls";  filenamedisplay = URLEncoder.encode(filenamedisplay,"UTF-8");  response.addHeader("Content-Disposition","attachment;filename=" + filenamedisplay);  OutputStream output = null;  FileInputStream fis = null;  try  {  output  = response.getOutputStream();  fis = new FileInputStream(realContextPath);  byte[] b = new byte[1024];  int i = 0;  while((i = fis.read(b)) > 0)  {  output.write(b, 0, i);  }  output.flush();  }  catch(Exception e)  {  System.out.println("Error!");  e.printStackTrace();  }  finally  {  if(fis != null)  {  fis.close();  fis = null;  }  if(output != null)  {  output.close();  output = null;  }  }  %>