?? baseuploadaction.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("上傳文件不存在");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -