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

📄 downloadfileaction.java

📁 负责公文的传输及一些处理功能
💻 JAVA
字号:
//Created by MyEclipse Struts// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.1/xslt/JavaClass.xslpackage com.example.web.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import javax.servlet.*;import java.io.*;import com.example.gw.attachment.Attachment;import com.example.gw.attachment.IAttachmentManager;/**  * MyEclipse Struts * Creation date: 08-02-2007 *  * XDoclet definition: * @struts.action validate="true" */public class DownLoadFileAction extends Action {		private String uploadPath;		public void setUploadPath(String uploadPath){		this.uploadPath = uploadPath;	}		public String getUploadPath(){		return uploadPath;	}		private IAttachmentManager attachmentManager;		public void setAttachmentManager(IAttachmentManager attachmentManager){		this.attachmentManager = attachmentManager;	}		public IAttachmentManager getAttachmentManager(){		return attachmentManager;	}		public static final String path_fgf =  File.separator;		// --------------------------------------------------------- Instance Variables	// --------------------------------------------------------- Methods	/** 	 * Method execute	 * @param mapping	 * @param form	 * @param request	 * @param response	 * @return ActionForward	 */	public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws IOException {	    ServletOutputStream outw= response.getOutputStream();	    try{	        String fileId=request.getParameter("fileId");	        String mimeType = "";	        String title = "";	        String path = "";	        String itemId = "";	        String fileName = "";	        Attachment dow=(Attachment)attachmentManager.getAttachment(fileId);		    mimeType = dow.getMimeType();		    title = dow.getTitle();		    path = dow.getPath();		    itemId = dow.getItemId().toString();		    fileName = dow.getFileName();	        response.setContentType(mimeType);	        response.setHeader("Content-Disposition","attachment;filename=\"" +new String(title.getBytes(),"iso-8859-1") + "\"");	        FileInputStream inp = new FileInputStream(getUploadPath() + path + itemId + path_fgf + fileName);	        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();	    }		// TODO Auto-generated method stub		return null;	}}

⌨️ 快捷键说明

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