filename = request.getParameter("filename");
response.setContentType("application/x-download");

String destfilename = URLEncoder.encode(filename, "UTF-8");

response.setHeader("Content-Disposition", "attachment; filename=\"" + destfilename + "\";");

 

需要说明的是,filename 不需要转换成UTF-8的原因是在服务器的 server.xml 的 Connector 节点设定了 URIEncoding 属性为 UTF-8 。见《JSP获取querystring的中文参数值 (2)》。

相关文章:

  • 2022-12-23
  • 2021-11-23
  • 2021-11-23
  • 2022-12-23
  • 2021-12-08
  • 2021-11-23
  • 2021-11-28
猜你喜欢
  • 2022-02-06
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2021-08-21
  • 2021-12-17
  • 2021-11-23
相关资源
相似解决方案