zoukankan      html  css  js  c++  java
  • Struts2 上传下载

    后台代码:
    public String getFileName() {
    String fileName = this.getRequest().getParameter("fileName");
    String downloadFileName = fileName;
    try {
    } catch (Exception e) {
    e.printStackTrace();
    }
    return downloadFileName;
    }
    // 下载的流
    public InputStream getInputStream() {
    String rootPath = CustomizedPropertyPlaceholderConfigurer
    .getContextProperty(SystemConstants.ROOT_PATH).toString();
    String name = this.getFileName();
    String realPath = rootPath + name;
    InputStream in = null;
    try {
    in = new FileInputStream(new File(realPath));
    return in;
    } catch (Exception e) {
    e.printStackTrace();
    System.out
    .println("Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.检查action中文件下载路径是否正确.");
    return null;
    }
    }
    public String download() {
    return "download";
    }

    struts.xml 配置文件设置

    <result name="download" type="stream">
    <!-- 该参数负责下载文件后的(另存为),默认保存的文件名-->
         <param name="contentDisposition">filename="${fileName}"</param>
    <!--下载文件流 -->
    <param name="inputName">inputStream</param>
    <!--缓存 -->
    <param name="bufferSize">4096</param>
    </result>
  • 相关阅读:
    数组分割成多个数组
    node-inspector调试工具
    6.17周六随写
    JavaScript设计模式
    JavaScript设计模式
    async源码学习
    Linux信号列表
    php常用Stream函数集介绍
    php进程控制
    php 单例模式与常驻服务
  • 原文地址:https://www.cnblogs.com/leonkobe/p/3895401.html
Copyright © 2011-2022 走看看