<%@ page contentType="text/html; charset=UTF-8"
%><%@ page import="java.util.*"
%><%@ page import="java.io.*"
%><%


    String ls_file = request.getParameter("ls_file");
    if(request.getSession().getAttribute("userInfo")==null){
    	response.getWriter().write("请登录后再下载");
		response.flushBuffer();
		return;
    }
	if(ls_file==null || ls_file.toUpperCase().indexOf("D:")==-1 || ls_file.indexOf("Tomcat6_mis/webapps")==-1 || ls_file.lastIndexOf(".zip")==-1){
		response.getWriter().write("无效的URL");
		response.flushBuffer();
		return;
	}
    
    ls_file =new String(ls_file.getBytes("ISO8859_1"),"utf-8");

    //文件写入到response
    
    String tt= ls_file;
    String filename="";
	if(tt==null || tt.trim().length()==0){
	  filename="demo.txt";
	}else{
		try{
			filename = tt.substring(tt.lastIndexOf("/")+1);
		}catch(Exception e){
			System.out.println("下载文件出错!");
			filename="demo.txt";
		}
	}
    response.setContentType("application/octet-stream");
    response.addHeader("Content-Disposition", "attachment; filename=\""+new String(filename.getBytes("gb2312"),"iso8859-1")+"\"");
    
	byte[] buffer = new byte[1024];
	InputStream is = null;
	try{
	if((ls_file!=null && ls_file!="") && ls_file.trim().length()>0){
		is = new FileInputStream(ls_file);
// 		HsBeforeOpeBusiness hsBeforeOpeBusiness = BusinessManager.getBusiness(HsBeforeOpeBusiness.class);
		String catalog_id = request.getParameter("catalog_id");
		Map<String,Object> m = new HashMap<String,Object>();
		m.put("CATALOG_ID",catalog_id);
// 		hsBeforeOpeBusiness.update_downloadCount(m);
	}else{
	    is = new FileInputStream("E:/Tomcat6_mis/webapps/jwmagic/hsdata/uploadfile/demo.txt");
	}
	while (is.read(buffer) >= 0) {
		response.getOutputStream().write(buffer);
	}
	}catch(Exception e){
	      response.addHeader("Content-Disposition", "attachment; filename=\"demo.txt\"");
	      is = new FileInputStream("E:/Tomcat6_mis/webapps/jwmagic/hsdata/uploadfile/demo.txt");
	      while (is.read(buffer) >= 0) {
		        response.getOutputStream().write(buffer);
	      }
		  System.out.println("找不到文件");
		  e.printStackTrace();
		}
	response.flushBuffer();
%>