struts2 上传与下载

1.Struts.xml

<action name="addfileAction" class="Action.addfileAction">
<interceptor-ref name="fileUpload">
<param name="maixmumSize">1024000000</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<param name="savePath">/save</param>
<result name="success">${path}/success.jsp</result>
<result name="input">/file/Fileup.jsp </result>
</action>

<action name="FlieDownAction" class="Action.FlieDownAction">
<result name="success" type="stream">
<param name="contentType">
application/octet-stream;charset=Iso8859-1
</param>
<param name="contentDisposition">、
attachment;filename="${downloadFileName}"
</param>
</result>
</action>

 

2.Action

public InputStream getInputStream() throws MalformedURLException{
String path="/save/"+filename;
return ServletActionContext.getServletContext().getResourceAsStream(path);
}

 

public String getDownloadFileName(){

String downloadFileName= new String(getFilename().getBytes("gbk"), "iso-8859-1");

return downloadFileName;

}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。