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

📄 baseuploadaction.java

📁 基于JAVA的学生就业信息网 实现对信息浏览 检索 审核 修改和删除
💻 JAVA
字号:
/*
 * Created on 2005-6-17
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.ug.sztz.webview.structs.actions.oa;

import java.io.InputStream;

import org.apache.struts.upload.FormFile;

import org.ug.sztz.domain.assistant.*;
import org.ug.sztz.domain.exception.IllegalServletConfigException;
import org.ug.sztz.domain.exception.IllegalLocalFileException;
import org.ug.sztz.domain.upload.UploadFileWriter;
/**
 * @author xix
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class BaseUploadAction  extends BaseAction {
	UrlConvertor urlConvertor;
	/**
	 * @return Get the physical path that stores student photos;
	 */
	
	private void init(){
		if(urlConvertor == null)
			urlConvertor = new UrlConvertor(this.getServlet().getServletConfig());
	}
	
	/**
	 * @param type   Define the type of file, which may be photo or attachment.
	 * @param fname  Define the file name of the file to be uploaded.
	 * @return The combination of the target path and the target filename.
	 */
	protected String getOutputPath(String fname) throws IllegalServletConfigException{
		init();
		
		String path = urlConvertor.getAbsoluteFile("/upload/", fname);
    
	    return path;
	}
	
	public void uploadFile(FormFile file) throws Exception{
		if(file != null && file.getFileSize() > 0)
		{
			String fname = file.getFileName();		      
		    
		    
		    InputStream stream;
			stream = file.getInputStream();
			//Set absolute output directory and file name
			String outputpath = getOutputPath(fname);		    
			    
		    //Output File immidiately
				
		    UploadFileWriter writer = new UploadFileWriter(stream, outputpath);
	        writer.save();
		}
		else
		{
			throw new IllegalLocalFileException("上传文件不存在");
		}
	}
	
	public void uploadFile(FormFile file,String fname) throws Exception{
		if(file != null && file.getFileSize() > 0)
		{
			InputStream stream;
			stream = file.getInputStream();
			//Set absolute output directory and file name
			String outputpath = getOutputPath(fname);		    
			    
		    //Output File immidiately
				
		    UploadFileWriter writer = new UploadFileWriter(stream, outputpath);
	        writer.save();
		}
		else
		{
			throw new IllegalLocalFileException("上传文件不存在");
		}
	}
}

⌨️ 快捷键说明

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