js:
{
text : '下载导入模板',
iconcls : 'import',
handler : function() {
window.location.href="../buinessplandownloadservlet";
}
}
java:
package com.sysware.customize.hd.investment.productionmaterialsmanagement.buinessplan;
import java.io.bufferedinputstream;
import java.io.bufferedoutputstream;
import java.io.file;
import java.io.fileinputstream;
import java.io.ioexception;
import java.io.printwriter;
import javax.servlet.servletexception;
import javax.servlet.servletoutputstream;
import javax.servlet.http.httpservlet;
import javax.servlet.http.httpservletrequest;
import javax.servlet.http.httpservletresponse;
public class buinessplandownservlet extends httpservlet {
private static final long serialversionuid = 1l;
protected void doget(httpservletrequest request,
httpservletresponse response) throws servletexception, ioexception {
this.dopost(request, response);
}
protected void dopost(httpservletrequest request,
httpservletresponse response) throws servletexception, ioexception {
string filepath = request.getsession().getservletcontext().getrealpath("") file.separator "template.files" file.separator "buinessplandown" file.separator "buinessplantempl.xls";
response.reset();
response.setcharacterencoding("utf-8");
file file = new file(filepath);
if (!file.exists()) {
printwriter out = response.getwriter();
out.print("{failure:true}");
return;
}
response.setcontenttype("application/x-msdownload");
response.setheader("content-disposition", "attachment;filename=" new string(file.getname().getbytes("gb2312"), "iso8859-1"));
servletoutputstream out = response.getoutputstream();
bufferedinputstream bis = new bufferedinputstream(new fileinputstream(filepath));
bufferedoutputstream bos = new bufferedoutputstream(out);
byte[] buff = new byte[2048];
int bytesread;
while (-1 != (bytesread = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesread);
}
if (bis != null) {
bis.close();
}
if (bos != null) {
bos.flush();
bos.close();
}
}
}
posted on 2013-03-05 14:11
紫蝶∏飛揚↗ 阅读(1071)
评论(0) 编辑 收藏 所属分类:
java