您的位置:首页 > Web前端 > JavaScript

jsp实现文件下载

2012-03-29 17:11 162 查看
jsmartuplod 架包的下载

<%

out.clear();

out = pageContext.pushBody();

SmartUpload su = new SmartUpload();

su.initialize(pageContext);//初始化

//su.setDenyPhysicalPath(true);

//设定contentDisposition为null以禁止浏览器自动打开文件, //保证点击链接后是下载文件。若不设定,则下载的文件扩展名为

//doc时,浏览器将自动用word打开它。扩展名为pdf时, //浏览器将用acrobat打开。

su.setContentDisposition(null); // 下载文件 String

String file = request.getParameter("download");

file=new String(file.getBytes("ISO-8859-1"),"GBK");

su.downloadFile("/upload/attachment/"+file);

response.getOutputStream().close();

out.close();

%

二:

-<result name="success" type="stream"> <param name="inputPath">/upload/attachment/</param>

<!--<param name="contentType">text/plain</param>-->

<param name="inputName">downloadFile</param> <param name="contentDisposition"> attachment;filename="${download}" </param> <param name="bufferSize">4096</param> </result>

private InputStream downloadFile;

public void setDownloadFile(InputStream downloadFile) {

this.downloadFile = downloadFile;

}

public InputStream getDownloadFile() {

return ServletActionContext.getServletContext().getResourceAsStream(

"upload/atachment/SecureCRT 常用命令 .txt");

}

public String getDownload() {

try {

download = new String(download.getBytes("iso-8859-1"), "UTF-8");

} catch (UnsupportedEncodingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return download;

}

public void setDownload(String download) {

this.download = download;

}

public String getInputPath() {

return inputPath;

}

public void setInputPath(String inputPath) {

this.inputPath = inputPath;

}

private String inputPath;

public String execute() {

return SUCCESS;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: