用struts2写的文件下载迅雷显示的文件后缀名是action???!!! 使用struts2写了一个文件下在的Action结果下点击文件下载的时候,迅雷弹出的下载框中显示的文件名为那个处理下载的Action,而用IE下载的时候文件名显示是正常的。请问这是什么原因,有什么办法可以解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没,好比我现在下载的文件名是demo.doc但是我点击下载按钮时,那下载的文件名称变成了我的action的方法名称。xxx.action这样的文件名称,我用IE可以正常下载文件,名称也是正确的。如果谁知道,希望给我一个解决的思路,我现在很急。 下载下来后就是文件名称了,主要下载action的配置文件中的attachment; filename这个2个有关attachment用了这个配置就会触发下载工具,不要就可以了filename是下载文件的名称也可以配置的 这是我那action里面的方法 /** * 下载附件方法 */ public String upLoadDow(){ HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); InputStream in = null; OutputStream os = null; try{ String path = request.getParameter("path"); System.out.println(path); path = new String(path.getBytes("iso-8859-1"),"UTF-8"); File file = new File(path); try{ in = new FileInputStream(file); os = response.getOutputStream(); }catch(FileNotFoundException ex){ ex.printStackTrace(); } response.setContentType("application/octet-stream; charset=UTF-8"); response.addHeader("Content-Disposition", "attachment; filename=" + new String(path.split("//")[1].getBytes("gb2312"),"ISO-8859-1")); int data = 0; while((data = in.read()) != -1){ os.write(data); } }catch(Exception ex){ // ex.printStackTrace(); }finally{ try { os.close(); in.close(); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("bbbbbb----------------"); e.printStackTrace(); } } return null; } 其他大网站都是这样的啊,去新浪ishare下载首歌,迅雷下载显示是.php啊,不是.mp3 这个。。 那个.php之类的 下载一会就变成正确地址了。。 我也遇到同样问题。貌似迅雷获取的是/后面的名字。可以下载正确的文件,只是无法获取文件的真实名字,获取的是action名字 把utf-8编码改为GBK即可。也不懂为什么 我用了struct2 的框架下载文件实现,使用迅雷也是action,但是使用IE就可以正常下载 //设置文件名 String downFileName = "测试报表.xls"; try { downFileName = java.net.URLEncoder.encode(downFileName, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } response.setHeader("Content-Disposition", "attachment;filename=" + downFileName);我这样 就没问题了·· 求救help, 希望大家能够进来瞧瞧 懂spring security的高手请进 请教各位高手 急急急!!! 招聘高级JAVA EE工程师! 网页贴纸条怎么制作的 问一下hibernate反转生成.hbm.xml的问题 大家进来看看,是一个导航的问题 关于IDBC的问题 简单的空字符判断问题!马上结帖!!! 最近遇到了一个问题。没有可用的缓冲区空间(数达到最大连接?),找不到原因处理。整个项目停止。数据也打不开。要怎么处理,各位大神帮忙看看。 泛型问题和jdbc事务问题 有人见过这么诡异的Servlet配置么?
下载下来后就是文件名称了,主要下载action的配置文件中的attachment; filename这个2个有关
attachment用了这个配置就会触发下载工具,不要就可以了
filename是下载文件的名称也可以配置的
/**
* 下载附件方法
*/
public String upLoadDow(){
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
InputStream in = null;
OutputStream os = null;
try{
String path = request.getParameter("path");
System.out.println(path);
path = new String(path.getBytes("iso-8859-1"),"UTF-8");
File file = new File(path);
try{
in = new FileInputStream(file);
os = response.getOutputStream();
}catch(FileNotFoundException ex){
ex.printStackTrace();
}
response.setContentType("application/octet-stream; charset=UTF-8");
response.addHeader("Content-Disposition", "attachment; filename=" + new String(path.split("//")[1].getBytes("gb2312"),"ISO-8859-1"));
int data = 0;
while((data = in.read()) != -1){
os.write(data);
}
}catch(Exception ex){
// ex.printStackTrace();
}finally{
try {
os.close();
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("bbbbbb----------------");
e.printStackTrace();
}
}
return null;
}
String downFileName = "测试报表.xls";
try {
downFileName = java.net.URLEncoder.encode(downFileName, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
response.setHeader("Content-Disposition", "attachment;filename=" + downFileName);
我这样 就没问题了··