<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.io.*"%>
<%@page import="java.io.*"%>
<%@ page import="com.censoft.db.DBUtil" %>
<%
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/";
    String file_path = "";
    InputStream in = null;
    Properties props = new Properties();
    try {
        in = DBUtil.class.getResourceAsStream("db.properties");
        props.load(in);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
    }
    String excel_model = props.getProperty("excel_model");
    System.out.println("excel_model="+excel_model);
    file_path=excel_model;
    java.io.FileInputStream fileInputStream = null;
    java.io.OutputStream os_out = null;
    File file_check = new File(file_path);
    if (file_check.exists()) {
        try {
            fileInputStream = new java.io.FileInputStream(
                    file_path);
            os_out = response.getOutputStream();
            byte tmpBytes[] = new byte[2 * 1024 * 1024];
            int totle = -1;
            response.reset();
            response.setContentType("applicate/octet-stream");
            response.setHeader(
                    "Content-Disposition",
                    "attachment; filename=model.xlsx");
            while ((totle = fileInputStream.read(tmpBytes)) != -1) {
                os_out.write(tmpBytes, 0, totle);
            }
        } catch (Exception e) {

            out.println(e);
            return;
        }finally{
            if (os_out != null) {
                try {os_out.flush();
                    os_out.close();
                } catch (Exception e) {
                }
            }
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (Exception e) {
                }
            }

        }
    }else{
        out.println("参数不能为空或没有查询到附件!");
        return;
    }
    out.clear();
    out = pageContext.pushBody();
%>
