- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%@page import="java.io.OutputStream"%>
- <%@page import="java.io.FileInputStream"%>
- <%@page import="java.io.File"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>下載</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
- <body>
- <%
- String filename = request.getParameter("filename");
- String paths = request.getRealPath("/");
- response.setContentType("application/x-download");
- response.addHeader("Content-Disposition", "attachment;filename="
- + filename);
- OutputStream op = null;
- FileInputStream in = null;
- try {
- op = response.getOutputStream();
- in = new FileInputStream(paths+"/upload/"+filename);
- byte[] b = new byte[1024];
- int i = 0;
- while ((i = in.read(b)) > 0) {
- op.write(b, 0, i);
- }
- op.flush();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (in != null) {
- in.close();
- in = null;
- }
- if (op != null) {
- op.close();
- op = null;
- }
- }
- File f = new File(application.getRealPath(filename));
- try {
- f.delete();
- f.deleteOnExit();
- } catch (Exception e) {
- }
- out.clear();
- out = pageContext.pushBody();
- %>
- </body>
- </html>