各位大侠
  Struts2 下载的时候,能不能把要下载的资源放在和项目不同的磁盘里呀.

解决方案 »

  1.   

    是不是想把STRUST2的包导入到项目中呢。
      

  2.   

    不是呀
    想做一个下载的功能  就是把从数据库中查出来的数据 ,写到Excel文件 ,然后给客户下载 , 但是Excel文件在别的磁盘建立的在项目里面建立Excel 文件的时候报错,所以想改用另外的方法
      

  3.   


    struts2下载
    只要提供的路径能准确找到文件 从文件获得输入流就可以了
      

  4.   

    你想怎么写下载?
    用struts2提供的下载功能?
    写个action 提供个获得InputStream的方法就行
    既然你能把文件写到其他地方 那路径就应该知道 或者保存起来
      

  5.   

        <action name="downListAction" class="com.net.action.MerAction" method="downList">
                <param name="inputPath">D:/Excel/tradeList.xls</param>
    <result name="success" type="stream">
                    <param name="contentType">application/vnd.ms-excel</param>
                    <param name="inputName">targetFile</param>
                    <param name="contentDisposition">filename="List.xls"</param>
                    <param name="bufferSize">1024</param>
                </result>
            </action> <param name="inputPath">D:/Excel/tradeList.xls</param>  这个配置路径运行的时候报错java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [targetFile] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
      

  6.   

    private String inputPath;
    public void setInputPath(String value)
    {
       inputPath = value;
    }public InputStream getTargetFile() throws Exception 
    {
        return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
    }public String downTradeList(){
        this.writeExcel();
        return SUCCESS;
    }