日期:2014-05-18  浏览次数:20820 次

DownloadAction下载文件
网上看了很多资料都是写用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;
 
 

}