----------------------------------下作下载方法一----------------------------------------------------------------------
action:
public String downTest(){
try {
name =new String(getFilename().getBytes("iso-8859-1"),"utf-8");
tname=java.net.URLEncoder.encode(name,"utf-8");
String path=ServletActionContext.getServletContext().getRealPath("/upload/"+name);
File file=new File(path); inputStream=new FileInputStream(file);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
struts.xml:
<!-- 下载中心控制器 -->
<action name="download" class="downloadAction">
<result name="downloadqry">/download.jsp</result>
<result name="success" type="stream">
<!-- 设置输入流 -->
<param name="inputstream">inputStream</param>
<!-- 设置下载的方式及文件名 -->
<param name="contentDisposition">attachment;filename=${tname}</param>
</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
jsp:
<a href="download!downTest?filename=${download.aname}" id="${download.aname}"style="color:#0099FF; cursor: pointer;" > 下载</a>