當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。