SSH下载的方法

----------------------------------下作下载方法一----------------------------------------------------------------------

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>

上一篇:ActiveMQ的使用笔记(基本实现原理)


下一篇:Linux 性能监控之命令行工具