67,512
社区成员
发帖
与我相关
我的任务
分享
//下载资料
public InputStream getDownloadFile(){
//获取相对路径
String path = datum.getDatumAddr();
int i = path.lastIndexOf("college");
String url = path.substring(i);
InputStream is = ServletActionContext.getServletContext().getResourceAsStream(url);
return is;
}
//文件下载
public String download(){
TDatum dt = dtbiz.findById(datum.getDatumId());
this.setDatum(dt);
this.setFileName(dt.getDatumName());
//下载次数加一
dt.setClick(dt.getClick()+1);
dtbiz.updateDatum(dt);
return "download";
}
<package name="datum" namespace="/datum" extends="struts-default">
<action name="datumAction" class="datumAction">
<result name="download" type="stream">
<param name="contentType">application/x-msdownload;charset=ISO8859-1</param>
<param name="contentDisposition">attachment;filename=${fileName}</param>
<param name="inputName">downloadFile</param>
</result>
</action>
</package>