• 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>
  • 相关阅读:
    git this exceeds GitHub's file size limit of 100.00 MB
    使用vue-cli创建vue工程
    【转】Visual Studio Code必备插件
    linux安装openssl
    Centos7离线安装mysql8
    使用nmon来按频率采集数据
    Mac下编译android4.0.4遇到的问题
    32位ubuntu16.4编译android4.1.1
    vmvare安装vmtools菜单灰色
    Substrate 使用
  • 原文地址:https://www.cnblogs.com/leonkobe/p/3895401.html
Copyright © 2020-2023  润新知