网上看了很多资料都是写用DownloadAction写上传下载的,我实现了上传,可是下载运河有问题。我上传时把文件名,存储路径存表里,下载时得到上传文件的名,和路径,根据网上说的http://blog.csdn.net/gaoguosheng/archive/2008/05/01/2358107.aspx
传入文件名,和路径下载,可是我都不知下到哪里去了,不知有什么问题,请这方面有经验的帮我看下,
这是下载面:
<table width="100%" height="40" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td background="img/fw-bg2.jpg"><table width="145" height="40" border="0" align="left" cellpadding="0" cellspacing="0">
                    <tr>
                      <td align="center" valign="middle" background="img/fw-bg.jpg">下载文件</td>
                    </tr>
                </table></td>
              </tr>
            </table>
<table width="98%" border="1" align="center" cellspacing="1" class="tablelistcontent">
    <tr>
      
      <th width="12%" align="center">文件名</th>
      <th width="12%" align="center">文件说明</th>
      <th width="12%" align="center">上传人</th>
      <th width="12%" align="center">上传日期</th>
      <th width="12%" align="center">使用对像</th>
      <th width="12%" align="center">下载</th>
     
    </tr>
    <logic:present name="list" scope="request">
    <logic:notEmpty name="list">
    <logic:iterate id="asset" name="list">   
     <tr>
      
      <td align="center">${asset[1] }</td>
      <td height="24"><div align="center">${asset[6] }</div></td>
      <td><div align="center"> ${asset[3] }</div></td>
      <td><div align="center"> ${asset[4] }</div></td>
      <td><div align="center"> ${asset[5] }</div></td>
      <td ><a href="<%=request.getContextPath() %>/download.do?filename=${asset[1] }&filepath=${asset[2] }"><img src="images/report/xinzen.gif" width="67" height="22" border="0"></a></td>     
     
    </tr>
</logic:iterate>
    </logic:notEmpty>
    </logic:present>
通过/download.do到了DownloadFileAction如下:
public class DownloadFileAction extends DownloadAction{
  protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        // TODO Auto-generated method stub
        String filename = request.getParameter("filename");
        String filepath = request.getParameter("filepath");
        FileViewer f =new FileViewer();
        String contentType=f.getContentType(filename);
       response.setHeader("Content-disposition", "attachment; filename="+filename);// 设置文件名称
        StreamInfo si = new ResourceStreamInfo(contentType,this.servlet.getServletContext(), filepath + filename);
        return si;
       
      }
  
  
}
可是这样下载没有呢?Action不是要返回个页面吗?

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【ypf8312】截止到2008-07-30 21:00:21的历史汇总数据(不包括此帖):
    发帖的总数量:9                        发帖的总分数:250                      每贴平均分数:27                       
    回帖的总数量:13                       得分贴总数量:4                        回帖的得分率:30%                      
    结贴的总数量:9                        结贴的总分数:250                      
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:100.00%                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    敬礼!

    取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=ypf8312
      

  2.   

    String filepath = request.getParameter("filepath"); 
    你这个filepath是你上传到服务器上的那个文件路径吗???
    另外就是contentType是否正确?
    仔细检查下这两个参数
    前段时间也做过一个这样的东西,不过用的是FileDownloadAction,楼主可以试试
      

  3.   

    filepath是我上传到服务器上的路径,contentType是文件的类型,我调试时看到是正确的,如果这两参数据没错,就这样就可以下载了吗?
      

  4.   

    奇怪,我这里报错;
    org.apache.struts.actions.DownloadAction.copy(DownloadAction.java:139)
    org.apache.struts.actions.DownloadAction.execute(DownloadAction.java:112)
    这个类不是导进去的吗?
      

  5.   

    OutputStream out = response.getOutputStream();
    其实在struts中也可以用servletOutputStream,直接把文件流write到servletOutputStream中去