jsp中文文件名下载问题,提示找不到此文件

xwt799023 2010-09-21 11:25:30
<a href="uploads/01需求分析.doc" target="_blank">点击下载</a>

当点“点击下载”提示找不到这个文件,就是因为中文文件名的问题,改成英文文件名就可以了,
请问如果不改成英文文件名的情况下,如何能正常下载呢
...全文
365 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
C_S_D_N_ktzhu 2010-11-10
  • 打赏
  • 举报
回复
学习下。。。。。。
zyujie 2010-09-21
  • 打赏
  • 举报
回复
楼主用的是tomcat吗,还是其它,修改tomcat的配置文件,改下编码!!!
tianshi1017 2010-09-21
  • 打赏
  • 举报
回复
关注中,估计礼拜六我也要做下载
xwt799023 2010-09-21
  • 打赏
  • 举报
回复
如何改法
dqsweet 2010-09-21
  • 打赏
  • 举报
回复
修改编码
xwt799023 2010-09-21
  • 打赏
  • 举报
回复
先试下,
chengjing123456 2010-09-21
  • 打赏
  • 举报
回复
学习。。。。。。。。。。
wwwtyb 2010-09-21
  • 打赏
  • 举报
回复
<%@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;

  }

  }

  %>
xwt799023 2010-09-21
  • 打赏
  • 举报
回复
是tomcat,能不能不改TOMCAT呀,其它方法最好

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧