隨筆-9  評論-168  文章-266  trackbacks-0
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 紫蝶∏飛揚↗ 閱讀(757) 評論(0)  編輯  收藏 所屬分類: JAVA

只有注冊用戶登錄后才能發表評論。


網站導航:
 
湖北快3号码表 用周易算彩票中了一等奖 股票开户哪家证券公司好佣金低 pk10最牛稳赚模式8码 内蒙古快三专家预测一 股票在线平台 十一选五走势图一定牛 四川快乐12近1000期开奖结果 山东11选5 五连号遗漏 快三玩法规则 广东南粤风采36选7开奖结果