计算机毕业设计中用js+html+java文件下载(一)

由于xml文件的格式比较特殊,因为和html存在冲突,所以在这里说明一下我用的是这个标签,因为 标签之间的内容不会被当作文档内容解析,而会被用等宽字体直接呈现。

@RequestMapping(value = "/previewFile", method = RequestMethod.GET)
    public String previewFile(String key, String fileFormat) {
        String url = getPath(key);
        String aimPath = url.replace(fileFormat, ".html");
        String encode = "";
        String fileContent = "";
        try {
            encode = EncodingDetect.getJavaEncode(url);
            fileContent = FileUtils.readFileToString(new File(url), encode);
        } catch (Exception e) {
            logger.warn("文件转换异常");
        }
        File newfile = new File(aimPath);
        String str = "<html><head></head><title>" + newfile.getName() + "</title><xmp style='margin-left: 5px;'>" + fileContent + "</xmp></html>";
        return str;
    }

本身是下载+预览的功能,这里主要介绍下载

<body>
<button onclick="downLoad()" id="btn">下载</button>
    <iframe id="mainframe" style="float: left;width:100%;height:96%;" frameborder="0"  scrolling="auto"></iframe>
</body>
function downLoad() {
        window.location.href = baseURL + "cms/systemModuleFileCollectNonCommon/downLoadFile?path=" + encodeURIComponent(filePath)+"&&ip="+ip;
    }

后端下载的java接口
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值