繁体中文
设为首页
加入收藏
当前位置:JSP技术首页 >> Java技巧及代码 >> 处理系统中的各类附件,上传下载

处理系统中的各类附件,上传下载

2005-01-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:  package com.highcom.object.common; import java.io.*;import javax.servlet.*;import com.jspsmart.upload.*;import com.highcom.hcgip.basic.common.*;import javax.servlet.http.*; /** * 处理系统中的各...

  package com.highcom.object.common;

import java.io.*;import javax.servlet.*;import com.jspsmart.upload.*;import com.highcom.hcgip.basic.common.*;import javax.servlet.http.*;

/** * 处理系统中的各类附件。这些附件被保存到在config.properties中attachmentpath指定的路径下。 *

Title: Objective Management System *

Description: *

Copyright: Copyright (c) 2004 * @version 1.0 */

public class FileKeeper extends javax.servlet.http.HttpServlet { public static String base_dir; static { base_dir = PropertiesReader.getConfigValue("attachmentpath"); }

public FileKeeper() { }

public static String getRelativePath(java.io.File abs_path){ String fullpath= abs_path.getAbsolutePath(); String new_fullpath = fullpath.replaceAll("/","\\").toLowerCase(); String new_base_dir = base_dir.replaceAll("/","\\").toLowerCase(); int i=new_fullpath.indexOf(new_base_dir); if(i 0) { response.setContentType(mime); } else { response.setContentType("application/*"); } response.setHeader("Content-Disposition", "attachment;filename=" + filename);

InputStream in = download(relative_path);

if (in == null) { Log.debug("文件" + filename + "不存在.", this); response.getOutputStream().close(); return; } byte[] b = new byte[1024]; int len; while ( (len = in.read(b)) > 0) { response.getOutputStream().write(b, 0, len); } in.close(); response.getOutputStream().flush(); response.getOutputStream().close();

}

}

责任编辑:admin
相关文章