⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downloadfileservlet.java

📁 OA典型例子
💻 JAVA
字号:
package com.sure.oa.down;/** * <p>Title: OA</p> * <p>Description: 项目</p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: surec</p> * @author mengzy * @version 1.0 */import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.util.*;import java.io.*;import com.sure.businesslogic.NotFoundException;import com.sure.dataabstraction.*;import com.sure.util.ConfigHand;public class downloadfileServlet  extends javax.servlet.http.HttpServlet{   public static final String path_fgf =  File.separator;   protected void doPost(HttpServletRequest req, HttpServletResponse rep) throws ServletException, IOException {      doGet(req,rep);   }  /**   * 在客户端打开附件   */  public void  doGet(HttpServletRequest req, HttpServletResponse rep) throws ServletException,IOException{      HttpServletRequest request=(HttpServletRequest)req;      javax.servlet.http.HttpServletResponse response=(HttpServletResponse)rep;      ServletOutputStream outw=response.getOutputStream();      try{         String docId=request.getParameter("docId");         downLoadFile dow=(downLoadFile)downLoadFileManager.getDownLoadFileList(docId).firstElement();         response.setContentType(dow.getMimeType());         response.setHeader("Content-Disposition","attachment;filename=\"" +new String(dow.getTitle().getBytes(),"iso-8859-1") + "\"");         //System.out.println(getUploadPath() + dow.getPath()+dow.getDocId()) ;         FileInputStream inp = new FileInputStream(getUploadPath() + dow.getPath()+dow.getDocId()+ path_fgf +dow.getTitle());         //FileInputStream inp = new FileInputStream(getUploadPath()+"/upload/6/2005/2/城区4[2005]1号/Doc1.doc");         int i;         byte [] buffer = new byte[1024];         while ( (i = inp.read(buffer)) != -1) {               outw.write(buffer, 0, i);         }         inp.close();         outw.flush();      }      catch (Exception e){         e.printStackTrace();      } finally {         outw.close();      }  }  /**   * 获得上传路径UploadPath   */  public static  String getUploadPath() {       /*String retValue="";       Properties property = null;       String configFile = "./conf/oc.conf";       File file = new File(configFile);       if (!file.exists()) {           throw new  RuntimeException(configFile + " file not found");       }       try {           property = new Properties();           property.load(new BufferedInputStream(new FileInputStream(file)));           retValue = property.getProperty("UploadPath");       } catch (IOException ex) {           System.err.println(ex.getMessage());       }       finally {           return  retValue;       }       */            return ConfigHand.getValue("UploadPath");   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -