<%@page contentType="text/html" pageEncoding="GBK"%>
<%@page import="java.io.*"%>
<html>
<body>
		<%
		if (session.getAttribute("d") != null&& request.getParameter("id").equals(session.getAttribute("d").toString())) {
			out.print(request.getServletPath());
			String fileName = request.getParameter("fileName");		//获取选中的文件名
			String path = request.getRealPath("/") + fileName;		//获取文件的绝对路径
			out.clear();
			out = pageContext.pushBody();
			response.setContentType("application/x-download");		//设置响应类型
			response.setHeader("Content-Disposition", "filename="+ fileName);
			InputStream in = new FileInputStream(path); 			//下载文件
			OutputStream outs = response.getOutputStream();		//创建输出流
			byte[] buf = new byte[1024];
			int len = 0;
			while ((len = in.read(buf)) > 0) {
				outs.write(buf, 0, len);
			}
			outs.close();
			in.close();
		} else {
			%>
			请不要通过非法链接下载此文件
			<%
				}
			%>
		</body>
</html>
