当前位置: 首页>>代码示例>>Java>>正文


Java ServletFileUpload.setProgressListener方法代码示例

本文整理汇总了Java中org.apache.commons.fileupload.servlet.ServletFileUpload.setProgressListener方法的典型用法代码示例。如果您正苦于以下问题:Java ServletFileUpload.setProgressListener方法的具体用法?Java ServletFileUpload.setProgressListener怎么用?Java ServletFileUpload.setProgressListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.fileupload.servlet.ServletFileUpload的用法示例。


在下文中一共展示了ServletFileUpload.setProgressListener方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MultipartUploadReader

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
 * Creates a new Reader for reading the given HTTP request. This must be a multipart request.
 * @param pFoxRequest
 */
public MultipartUploadReader(FoxRequest pFoxRequest) {
  try {
    // New file upload handler
    mServletFileUploadUpload = new ServletFileUpload();

    // Create a progress listener for this upload
    mFiletransferProgressListener = new FiletransferProgressListener();

    // Attach the progress listener to this upload
    mServletFileUploadUpload.setProgressListener(mFiletransferProgressListener);
    //mUploadInfo.setProgressListener(mFiletransferProgressListener);

    // Parse the upload request
    mItemIterator = mServletFileUploadUpload.getItemIterator(pFoxRequest.getHttpRequest());
  }
  catch (Throwable ex) {
    throw new ExInternal("Error encountered while trying to initialise a file upload work item.\nOriginal error: " + ex.getMessage());
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:24,代码来源:MultipartUploadReader.java

示例2: newFileUpload

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
protected FileUpload newFileUpload(FileItemFactory fileItemFactory) {
    
    ServletFileUpload upload = new ServletFileUpload(fileItemFactory); 
    upload.setSizeMax(-1); 
    if (request != null) {
        // 注入监听
        FileUploadProgressListener uploadProgressListener = new FileUploadProgressListener();
        upload.setProgressListener(uploadProgressListener);
        request.getSession().setAttribute(C.UPLOAD_PROGRESS_LISTENER_KEY, uploadProgressListener);
    }
    return upload;
}
 
开发者ID:PekingGo,项目名称:ipayquery,代码行数:14,代码来源:CustomMultipartResolver.java

示例3: getFileUploadComponent

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
private ServletFileUpload getFileUploadComponent()
{
    DiskFileItemFactory dif=new DiskFileItemFactory();

    if(factorySizeThreshold!=DEFAULT_SIZE_THRESHOLD)
    {
        dif.setSizeThreshold(factorySizeThreshold);
    }
    if(factoryRepository!=null)
    {
        dif.setRepository(new File(factoryRepository));
    }
    if(factoryCleaningTracker!=null)
    {
        dif.setFileCleaningTracker(factoryCleaningTracker);
    }

    ServletFileUpload sfu=new ServletFileUpload(dif);

    if(sizeMax!=NO_LIMIT_SIZE_MAX)
    {
        sfu.setSizeMax(sizeMax);
    }
    if(fileSizeMax!=NO_LIMIT_FILE_SIZE_MAX)
    {
        sfu.setFileSizeMax(fileSizeMax);
    }
    if(servletHeaderencoding!=null)
    {
        sfu.setHeaderEncoding(servletHeaderencoding);
    }
    if(servletProgressListener!=null)
    {
        sfu.setProgressListener(servletProgressListener);
    }

    return sfu;
}
 
开发者ID:ProteanBear,项目名称:ProteanBear_Java,代码行数:39,代码来源:FileUploader.java

示例4: parse

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@SuppressWarnings({"unchecked", "PMD.CyclomaticComplexity" })
public void parse(HttpServletRequest servletRequest, String saveDir) throws IOException {
    DiskFileItemFactory fac = new DiskFileItemFactory();
    fac.setSizeThreshold(0);
    if (saveDir != null) {
        fac.setRepository(new File(saveDir));
    }
    ProgressMonitor monitor = null;
    try {
        ServletFileUpload upload = new ServletFileUpload(fac);
        upload.setSizeMax(maxSize);
        monitor = new ProgressMonitor();
        upload.setProgressListener(monitor);
        String uploadKey = getUploadKey(servletRequest);
        servletRequest.getSession().setAttribute(uploadKey, monitor);
        List<FileItem> items = (List<FileItem>) upload.parseRequest(createRequestContext(servletRequest));
        for (FileItem item : items) {
            LOG.debug((new StringBuilder()).append("Found item ").append(item.getFieldName()).toString());
            if (item.isFormField()) {
                handleFormField(servletRequest, item);
            } else {
                handleFileUpload(item);
            }
        }
        handleChunkedUploadHeaders(servletRequest);
    } catch (FileUploadException e) {
        if (monitor != null) {
            monitor.abort();
        }
        LOG.warn("Error processing upload", e);
        errors.add(e.getMessage());
    }
}
 
开发者ID:NCIP,项目名称:caarray,代码行数:37,代码来源:MonitoredMultiPartRequest.java

示例5: doPost

import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();

		out.println("Hello<br/>");

		boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
		if (!isMultipartContent) {
			out.println("You are not trying to upload<br/>");
			return;
		}
		out.println("You are trying to upload<br/>");

		FileItemFactory factory = new DiskFileItemFactory();
		ServletFileUpload upload = new ServletFileUpload(factory);
//		upload.setSizeMax(MAX_UPLOAD_IN_MEGS * 1024 * 1024);
		
		ProgressListener testProgressListener = new ProgressListener();
		upload.setProgressListener(testProgressListener);

		HttpSession session = request.getSession();
		session.setAttribute("testProgressListener", testProgressListener);
		
		try {
			List<FileItem> fields = upload.parseRequest(request);
			out.println("Number of fields: " + fields.size() + "<br/><br/>");
			Iterator<FileItem> it = fields.iterator();
			if (!it.hasNext()) {
				out.println("No fields found");
				return;
			}
			out.println("<table border=\"1\">");
			while (it.hasNext()) {
				out.println("<tr>");
				FileItem fileItem = it.next();
				boolean isFormField = fileItem.isFormField();
				if (isFormField) {
					out.println("<td>regular form field</td><td>FIELD NAME: " + fileItem.getFieldName() + 
							"<br/>STRING: " + fileItem.getString()
							);
					out.println("</td>");
				} else {
					out.println("<td>file form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
//							"<br/>STRING: " + fileItem.getString() +
							"<br/>NAME: " + fileItem.getName() +
							"<br/>CONTENT TYPE: " + fileItem.getContentType() +
							"<br/>SIZE (BYTES): " + fileItem.getSize() +
							"<br/>TO STRING: " + fileItem.toString()
							);
					out.println("</td>");
				}
				out.println("</tr>");
			}
			out.println("</table>");
		} catch (FileUploadException e) {
			out.println("Error: " + e.getMessage());
			e.printStackTrace();
		}
	}
 
开发者ID:szaqal,项目名称:KitchenSink,代码行数:63,代码来源:UploadServlet.java


注:本文中的org.apache.commons.fileupload.servlet.ServletFileUpload.setProgressListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。