piziliu 2011-03-18 16:47
浏览 203
已采纳

IE6下的下载问题(把XXX放到桌面功能)

如题,在FF下测试是正常的,chrome 也正常,IE7以上版本也正常,惟独IE6不行。

可在 http://www.tuanhaoduo.com 主页左上角上测试(绝非广告贴,还请管理员谅解)。

求解,谢谢了。

@Controller
@RequestMapping("/*.do")
public class IndexController extends BaseController {
        
        // 省略其他无关函数
        
        @RequestMapping
    public String down4desk(HttpServletRequest request,
            HttpServletResponse response) {
        response.setContentType("application/x-msdownload");
        
        String content = "";
        try {
            response.setHeader("Content-Disposition", "attachment;filename="
                    + new String("团好多.url".getBytes("gbk"), "iso-8859-1"));
            content = FileUtil.read(Constant.HTMLROOT + "tuanhaoduo.url", true,
                    "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return renderText(request, response, content);
    }
}




FileUtil类中的相关函数:

        /**
     * 读取文件
     * 
     * @param filename
     * @param isSet
     *            是否需要加上换行
     * @param strCode
     *            编码,如GBK
     * @return
     * @throws IOException
     */
    public static String read(String filename, boolean isSet, String strCode)
            throws IOException {
        File file = new File(filename);
        InputStreamReader read = new InputStreamReader(
                new FileInputStream(file), strCode);
        BufferedReader reader = new BufferedReader(read);
        String line = "";
        StringBuffer readfile = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            readfile.append(line);
            if (isSet)
                readfile.append("\r\n");
        }
        reader.close();
        read.close();
        return readfile.toString();
    }



其中,Constant.HTMLROOT 的值从配置中取得,值为:/home/htmlfile/tuan/
模板语言用到了 apache volicity, 控制器用到了 springMVC。

 

把标签、技术分类弄错了,又修改不了,真是不好意思。

 

 

  • 写回答

6条回答

  • changchanghust 2011-03-19 20:00
    关注

    我在ubuntu下试了一下下载一个.url的文件,ff是正常的名字。
    如果你有截包的工具的话,如fiddler,截包看一下,浏览器接收到的contentTye和Content-Disposition是不是正确的?

    下面是我的测试代码跟传输数据有关的部分。

    [code="java"]InputStream is = null;
    OutputStream os = null;
    try {
    resp.setContentType("application/octet-stream");
    resp.setHeader("Content-disposition", "attachment;filename=" + new String(fn.getBytes("utf-8"), "iso-8859-1"));
    is = new FileInputStream(file);
    os = resp.getOutputStream();

            int count = 0;  
            byte[] buffer = new byte[8192];  
            while((count = is.read(buffer)) != -1){  
                os.write(buffer, 0, count);   
            } 
            os.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }[/code]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧