zoukankan      html  css  js  c++  java
  • struts2文件下载

    在weblogic中,超级链接不能下载,而是直接打开,所以我用struts2的文件下载.

    1.action 的名字必须为donwload;

    2.action的配置如下:

    <action name="download" class="subjectAction">
          <!-- 给action注入inputPath(资源文件的位置) -->
          <param name="inputPath">/doc/myMianshiti.doc</param>
          <!-- 指输入流定流   -->
          <result name="success" type="stream">
           <!-- 文件类型 -->
           <param name="contentType">application/msword</param>
           <!-- 下边的意思是说文件下载的输入流是"targetFile", struts2会调用它的get方法
              也就是说实际是有getTargetFile输出流的内容的
            -->
           <param name="inputName">targetFile</param>
          </result>
         </action>

    3.action类中.必须有String inputPath,及其set方法;必须有getTargetFile方法返回流.(因为在配置文件中是这么指定的!)

       返回流:return ServletActionContext.getServletContext().getResourceAsStream(inputPath);

    4.补充:contentType 见:http://www.cnblogs.com/chenghm2003/archive/2008/10/19/1314703.html

  • 相关阅读:
    sys.stdout.flush-倒计时
    wget 网站扒取
    万能英数脚本
    sample function
    get_time
    读取指定行
    request设置cookies
    resize2fs
    闭包与认识装饰器
    函数的名称空间与作用域
  • 原文地址:https://www.cnblogs.com/yanjunwu/p/3078308.html
Copyright © 2011-2022 走看看