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>
  • 相关阅读:
    properties的编码问题
    在Spring中读取properties文件
    Intellij IDEA常用配置记录
    基于Shiro的登录功能 设计思路
    在SpringMVC中操作Session、Request、Response对象
    使用MockMVC与Junit进行单体测试
    django: form fileupload
    django: form
    django: db
    django: db
  • 原文地址:https://www.cnblogs.com/leonkobe/p/3895401.html
Copyright © 2011-2022 走看看