lq3769 2010-05-20 16:20
浏览 274
已采纳

struts2文件下载异常

异常信息: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.

 

struts.xml

<action name="download" class="upload.DownLoadAction">
     <param name="inputPath">\WEB-INF\uploadFile\Criteria.txt</param>
     <result name="success" type="stream"></result>
     <param name="contentType">text/txt</param>
     <param name="inputName">downloadFile</param>
     <param name="contentDisposition">attachment;filename="Criteria.txt"</param>
     <param name="bufferSize">4096</param>
</action>

 DownLoadAction.action

package upload;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DownLoadAction extends ActionSupport{

    private String inputPath;
    
    
    public String getInputPath() {
        return inputPath;
    }


    public void setInputPath(String inputPath) {
        this.inputPath = inputPath;
    }

                //这个getDownloadFile()方法没进入
    public InputStream getDownloadFile()
    {
        System.out.println("inputPath"+inputPath);
        System.out.println(ServletActionContext.getServletContext().getResourceAsStream(inputPath));
         return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
    }

    @Override
    public String execute() throws Exception {
        System.out.println("ss");
        return SUCCESS;
    }

    
}

 麻烦各位帮我看看,谢谢啦!

  • 写回答

3条回答 默认 最新

  • 拽拽的初行者 2010-05-20 16:29
    关注

    [b] 你的result配置错误。 param应该result中包裹着[/b]

    [code="xml"]
    text/txt

    downloadFile

    attachment;filename="Criteria.txt"

    4096
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型