| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1652 人关注过本帖
标题:struts文件下载问题
只看楼主 加入收藏
fujinliang
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-3-30
结帖率:0
收藏
 问题点数:0 回复次数:3 
struts文件下载问题
ACTION中:
public InputStream getTargetFile() throws Exception{
        return ServletActionContext.getServletContext().getResourceAsStream("upload\\"+getDownloadFileName());
    }
    public String getDownloadFileName(){
        
         String downFileName=ServletActionContext.getRequest().getParameter("name");
        try{
            downFileName=new String(downFileName.getBytes(),"ISO8859-1");
        }catch(UnsupportedEncodingException e){
            e.printStackTrace();
        }
        return downFileName;
    }
怎么name得到的参数是中文就有问题呢,,,拔出异常
搜索更多相关主题的帖子: struts 文件 
2008-12-01 22:42
linwu_2006
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2008-4-10
收藏
得分:0 
回复 楼主 fujinliang 的帖子
有跟楼主同样的问题。。。。本人用JSP写个下载,求高手帮帮忙
<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@ page import="*" %>
<%
request.setCharacterEncoding("GBK");
String tempFileName="1.txt";//文件名字

byte b[]=new byte[10240];
//建立文件
File fileLoad=new File(application.getRealPath("/Upload"),tempFileName);

response.setHeader("Content-disposition","attachment;filename="+tempFileName);
response.setContentType("application/x-msdownload");

long fileLength=fileLoad.length();
String length=String.valueOf(fileLength);
response.setHeader("Content_Length",length);

//读取文件并发送到客户端下载
OutputStream o=response.getOutputStream();
FileInputStream in=new FileInputStream(fileLoad);
int n=0;
while((n=in.read(b))!=-1){
    o.write(b,0,n);
}
in.close();
o.close();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>下载</title>
</head>
<body>
</body>
</html>

为什么那个tempFileName是中文的时候就不能下载呢?
2008-12-02 20:33
598156412
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2007-12-16
收藏
得分:0 
1楼:
 downFileName=new String(downFileName.getBytes(),"gbk");
或者 downFileName=new String(downFileName.getBytes(),"gb2312");
 downFileName=new String(downFileName.getBytes(),"ISO8859-1");这种只支持英语。
2008-12-04 14:16
快速回复:struts文件下载问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020972 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved