[转]JSP文件下载

<%
    response.setContentType("application/x-download");
    String filedownload="/upDir/sass_by_CandisSara_jpgm.jpg";
    String filedisplay="sass_by_CandisSara_jpgm.jpg";
    String filenamedisplay=URLEncoder.encode(filedisplay,"GBK");
    response.addHeader("Content-Disposition","attachment;filename="+filedisplay);
    try{
    RequestDispatcher dis=application.getRequestDispatcher(filedownload);
    if(dis!=null){
    dis.forward(request,response);
    }
    response.flushBuffer();
    }catch(Exception e){
    e.printStackTrace();
    }finally{
    out.clear();//最后两行关闭输出流,否则报错
    out=pageContext.pushBody();
    }
     %>

你可能感兴趣的:(jsp)