customfileuploadbean.java
来自「OperaMasks是一种基于J2EE的Web开发技术」· Java 代码 · 共 71 行
JAVA
71 行
package demo.fileupload;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.component.widget.fileupload.impl.UIFileUploadDialog;
@ManagedBean(name="CustomFileUploadBean", scope=ManagedBeanScope.REQUEST)
public class CustomFileUploadBean{
@Bind
private UIFileUploadDialog fileupload;
@Action
public void click(){
fileupload.show();
}
@Action
public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException{
// ServletFileUpload upload = new ServletFileUpload();
// InputStream stream = null;
// BufferedInputStream bis = null;
// BufferedOutputStream bos = null;
// try {
// if (ServletFileUpload.isMultipartContent(request)) {
// upload.setSizeMax(1024*1024);
// FileItemIterator iter = upload.getItemIterator(request);
// while (iter.hasNext()) {
// FileItemStream item = iter.next();
// stream = item.openStream();
// if (!item.isFormField()) {
// String filename = new File(item.getName()).getName();
// bis = new BufferedInputStream(stream);
// bos = new BufferedOutputStream(new FileOutputStream(new File("c:/" + filename)));
// Streams.copy(bis, bos, true);
// }
// }
// fileupload.uploadSuccess(response);
// }
// } catch (FileUploadException e) {
// fileupload.uploadFailed(response, e.getMessage());
// } finally{
// if(stream != null){
// try{
// stream.close();
// }catch(Exception e){}
// }
// if(bis != null){
// try{
// bis.close();
// }catch(Exception e){}
// }
// if(bos != null){
// try{
// bos.close();
// }catch(Exception e){}
// }
// }
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?