u010272041 2015-01-21 03:47 采纳率: 0%
浏览 1634

求大神看看用struts2为什么不能下载

JSP

 <tr>
                <td colspan="4" align="right"><s:form action="DownloadAction"
                        method="post">
                        <s:submit value="下载" />
                    </s:form></td>
            </tr>

action

 public class DownLoadAction extends ActionSupport {
    private static final long serialVersionUID = 1L;

    public InputStream getDownloadFile() throws Exception {
        // 获得ServletContext对象
        ServletContext servletContext = ServletActionContext
                .getServletContext();
        // 返回被下载文件的InputStream对象
        return servletContext
                .getResourceAsStream("E:/J2EEExercise/J2EEExercise_4/result.txt");
    }

    public String execute() throws Exception {
        return SUCCESS;
    }
}

struts.xml

 <action name="DownloadAction" class="action.DownLoadAction">
            <result name="success" type="stream">
                <!-- 指定被下载文件的类型 -->
                <param name="contentType">text/plain</param>
                <!-- 指定活得被下载文件的InputStream对象的Action属性 -->
                <param name="inputName">downloadFile</param>
                <!-- 指定被下载的文件名 -->
                <param name="contentDisposition">attachment,filename="result.txt"</param>
                <!-- 指定被下载文件时所使用的缓冲区大小 -->
                <param name="bufferSize">1024</param>
            </result>
        </action>

点击下载后一直弹出这个错误

  Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
  • 写回答

3条回答 默认 最新

  • threenewbee 2015-01-21 04:23
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题