/** * 方法(受保护)<br> * 名称: init<br> * 描述: Servlet初始化时调用此方法,初始化连接器以及数据层接口的实现方法<br> * * @throws javax.servlet.ServletException */ @Override public void init() throws ServletException { super.init(); //初始化文件上传器 this.fileUploader=new FileUploader(UPLOAD_PATH,ACCEPT_TYPES,MAX_SIZE,MAX_FILE_SIZE); // 根据实际情况设置对象属性(可选) //设置名字生成器 /*this.fileUploader.setFileNameGenerator(new FileNameGenerator() { @Override public String generate(FileItem item, String suffix) { return String.format("%d_%d", item.hashCode(), item.get().hashCode()); } });*/ //设置进度监听器 this.fileUploader.setServletProgressListener( new ProgressListener() { @Override public void update(long pBytesRead, long pContentLength, int pItems) { System.out.printf("%d: length -> %d, read -> %d.\n",pItems,pContentLength,pBytesRead); } } ); }
/** * 方法(受保护)<br/> * 名称: init<br/> * 描述: Servlet初始化时调用此方法,初始化连接器以及数据层接口的实现方法<br/> * * @throws javax.servlet.ServletException */ @Override public void init() throws ServletException { super.init(); //初始化文件上传器 this.fileUploader=new FileUploader(UPLOAD_PATH,ACCEPT_TYPES,MAX_SIZE,MAX_FILE_SIZE); this.processor=new ImageProcessor(); // 根据实际情况设置对象属性(可选) //设置名字生成器 /*this.fileUploader.setFileNameGenerator(new FileNameGenerator() { @Override public String generate(FileItem item, String suffix) { return String.format("%d_%d", item.hashCode(), item.get().hashCode()); } });*/ //设置进度监听器 this.fileUploader.setServletProgressListener( new ProgressListener() { @Override public void update(long pBytesRead, long pContentLength, int pItems) { System.out.printf("%d: length -> %d, read -> %d.\n",pItems,pContentLength,pBytesRead); } } ); }
public void addListener(String id, ProgressListener listener) { String key = getKey(id); sessionService.setAttribute(key, listener); }
public ProgressListener getUploadFileListener() { return __uploadFileListener; }
/** * 设置上传组件的处理进程监听器,参考:{@link ServletFileUpload#setProgressListener(ProgressListener)} * * @param servletProgressListener */ public void setServletProgressListener( ProgressListener servletProgressListener) { this.servletProgressListener=servletProgressListener; }
/** * Creates a new instance with the given listener * and content length. * * @param pListener The listener to invoke. * @param pContentLength The expected content length. */ ProgressNotifier(ProgressListener pListener, long pContentLength) { listener = pListener; contentLength = pContentLength; }
/** * @return 文件上传状态监听器 */ ProgressListener getUploadFileListener();
/** * 获取上传组件的处理进程监听器,参考:{@link ServletFileUpload#getProgressListener()} * * @return */ public ProgressListener getServletProgressListener() { return servletProgressListener; }
/** Creates a new instance with the given listener * and content length. * @param pListener The listener to invoke. * @param pContentLength The expected content length. */ ProgressNotifier(ProgressListener pListener, long pContentLength) { listener = pListener; contentLength = pContentLength; }