JSP 로 워드 파일 다운로드(IE 로 직접 열지 않 음)

<%@page import="java.util.*"%><%@page import="java.io.*"%><%@page import="java.net.*"%><%    String filename = "";    if (request.getParameter("file") != null) {        filename =     request.getParameter("file");    }    response.setContentType("application/msword");    response.setHeader("Content-disposition","attachment; filename="+filename);    BufferedInputStream bis = null;    BufferedOutputStream bos = null;    try {        bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename)));        bos = new BufferedOutputStream(response.getOutputStream());        byte[] buff = new byte[2048];        int bytesRead;        while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {            bos.write(buff,0,bytesRead);        }    } catch(final IOException e) {        System.out.println("IOException 이 나타 납 니 다."+e);    } finally {        if (bis != null)            bis.close();        if (bos != null)            bos.close();    }    return;%>

좋은 웹페이지 즐겨찾기