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


Java FileItem.isFormField方法代码示例

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


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

示例1: upload

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
/**
 * 文件上传处理类
 *
 * @return {@link UploadResult}
 * @throws Exception 抛出异常
 */
public UploadResult upload() throws Exception {
    boolean multipartContent = ServletFileUpload.isMultipartContent(request);
    if (!multipartContent) {
        throw new RuntimeException("上传表单enctype类型设置错误");
    }

    List<TextFormResult> textFormResultList = Lists.newArrayList();
    List<FileFormResult> fileFormResultList = Lists.newArrayList();

    List<FileItem> fileItems = upload.parseRequest(request);
    for (FileItem item : fileItems) {
        if (item.isFormField())
            textFormResultList.add(processFormField(item));
        else
            fileFormResultList.add(processUploadedFile(item));
    }
    return new UploadResult(textFormResultList, fileFormResultList);
}
 
开发者ID:glameyzhou,项目名称:scaffold,代码行数:25,代码来源:Uploader.java

示例2: extractAttachments

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
/**
 * extracts attachments from the http request.
 *
 * @param httpRequest
 *            request containing attachments DefaultMultipartHttpServletRequest is supported
 * @param request
 *            {@link Request}
 * @return ids of extracted attachments
 * @throws IOException
 *             throws exception if problems during attachments accessing occurred
 * @throws FileUploadException
 *             Exception.
 * @throws AttachmentIsEmptyException
 *             Thrown, when the attachment is of zero size.
 * @throws AuthorizationException
 *             in case there is no authenticated user
 */
private List<AttachmentResource> extractAttachments(HttpServletRequest httpRequest,
        Request request) throws FileUploadException, IOException,
        AttachmentIsEmptyException, AuthorizationException {
    List<AttachmentResource> result = new ArrayList<>();
    if (httpRequest.getContentType().startsWith(AttachmentResourceHelper.MULTIPART_FORM_DATA)) {
        FileItemFactory factory = new DiskFileItemFactory();
        FileUpload upload = new FileUpload(factory);
        List<FileItem> items = upload.parseRequest(new ServletRequestContext(httpRequest));
        for (FileItem file : items) {
            if (!file.isFormField()) {
                AttachmentTO attachmentTo = new AttachmentStreamTO(file.getInputStream(),
                        AttachmentStatus.UPLOADED);
                AttachmentResourceHelper.assertAttachmentSize(file.getContentType(),
                        file.getSize(), false);
                attachmentTo.setMetadata(new ContentMetadata());
                attachmentTo.getMetadata().setFilename(getFileName(file.getName()));
                attachmentTo.getMetadata().setContentSize(file.getSize());
                result.add(persistAttachment(request, attachmentTo));
            }
        }
    }
    return result;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:41,代码来源:AttachmentResourceHandler.java

示例3: getMultiParameter

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
/**
 * Retrieve a parameter passed to the servlet as part of a multi part content.
 * 
 * @param parameter
 *          the name of the parameter to be retrieved
 * @param requestFilter
 *          filter used to validate the input against list of allowed inputs
 * @return String containing the value of the parameter. Empty string if the content is not
 *         multipart or the parameter is not found.
 */
public String getMultiParameter(String parameter, RequestFilter requestFilter) {
  if (!isMultipart || items == null)
    return "";
  Iterator<FileItem> iter = items.iterator();
  while (iter.hasNext()) {
    FileItem item = iter.next();
    if (item.isFormField() && item.getFieldName().equals(parameter)) {
      try {
        String value = item.getString("UTF-8");
        filterRequest(requestFilter, value);
        return value;
      } catch (Exception ex) {
        ex.printStackTrace();
        return "";
      }
    }
  }
  return "";
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:30,代码来源:VariablesBase.java

示例4: extractAttachments

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
/**
 * extracts attachments from the http request.
 *
 * @param httpRequest
 *            request containing attachments DefaultMultipartHttpServletRequest is supported
 * @param request
 *            {@link Request}
 * @return ids of extracted attachments
 * @throws MaxLengthReachedException
 *             attachment size is to large
 * @throws IOException
 *             throws exception if problems during attachments accessing occurred
 * @throws FileUploadException
 *             Exception.
 * @throws AttachmentIsEmptyException
 *             Thrown, when the attachment is of zero size.
 * @throws AuthorizationException
 *             in case there is no authenticated user
 */
private List<AttachmentResource> extractAttachments(HttpServletRequest httpRequest,
        Request request) throws MaxLengthReachedException, FileUploadException, IOException,
        AttachmentIsEmptyException, AuthorizationException {
    List<AttachmentResource> result = new ArrayList<AttachmentResource>();
    if (httpRequest.getContentType().startsWith(AttachmentResourceHelper.MULTIPART_FORM_DATA)) {
        FileItemFactory factory = new DiskFileItemFactory();
        FileUpload upload = new FileUpload(factory);
        List<FileItem> items = upload.parseRequest(new ServletRequestContext(httpRequest));
        for (FileItem file : items) {
            if (!file.isFormField()) {
                AttachmentTO attachmentTo = new AttachmentStreamTO(file.getInputStream(),
                        AttachmentStatus.UPLOADED);
                AttachmentResourceHelper.assertAttachmentSize(file.getContentType(),
                        file.getSize(), false);
                attachmentTo.setMetadata(new ContentMetadata());
                attachmentTo.getMetadata().setFilename(getFileName(file.getName()));
                attachmentTo.getMetadata().setContentSize(file.getSize());
                result.add(persistAttachment(request, attachmentTo));
            }
        }
    }
    return result;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:43,代码来源:AttachmentResourceHandler.java

示例5: getHashtable

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
public Hashtable getHashtable(HttpServletRequest request)
        throws FileUploadException, IOException {
    Hashtable ht = new Hashtable();
    DiskFileUpload upload = new DiskFileUpload();
    List fileItems = upload.parseRequest(request);
    Iterator iter = fileItems.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        if (item.isFormField()) {
            ht.put(item.getFieldName(), item.getString());
        } else {
            if (item.getName().equals("")) {
                //ht.put(item.getFieldName(), null);
            } else if (item.getSize() == 0) {
                //ht.put(item.getFieldName(), null);
            } else {
                ht.put(item.getFieldName(), item.getInputStream());
            }
        }
    }
    return ht;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:23,代码来源:PartnershipPageletAdaptor.java

示例6: extractAttachments

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
/**
 * extracts attachments from the http request.
 *
 * @param httpRequest
 *            request containing attachments DefaultMultipartHttpServletRequest is supported
 * @param request
 *            {@link Request}
 * @return ids of extracted attachments
 * @throws MaxLengthReachedException
 *             attachment size is to large
 * @throws IOException
 *             throws exception if problems during attachments accessing occurred
 * @throws FileUploadException
 *             Exception.
 * @throws AuthorizationException
 *             in case there is no authenticated user
 */
private List<AttachmentResource> extractAttachments(HttpServletRequest httpRequest,
        Request request) throws MaxLengthReachedException, FileUploadException, IOException,
        AuthorizationException {
    List<AttachmentResource> result = new ArrayList<AttachmentResource>();
    if (httpRequest.getContentType().startsWith(AttachmentResourceHelper.MULTIPART_FORM_DATA)) {
        FileItemFactory factory = new DiskFileItemFactory();
        FileUpload upload = new FileUpload(factory);
        List<FileItem> items = upload.parseRequest(new ServletRequestContext(httpRequest));
        for (FileItem file : items) {
            if (!file.isFormField()) {
                AttachmentTO attachmentTo = new AttachmentStreamTO(file.getInputStream(),
                        AttachmentStatus.UPLOADED);
                AttachmentResourceHelper.assertAttachmentSize(file.getContentType(),
                        file.getSize(), false);
                attachmentTo.setMetadata(new ContentMetadata());
                attachmentTo.getMetadata().setFilename(getFileName(file.getName()));
                attachmentTo.getMetadata().setContentSize(file.getSize());
                result.add(persistAttachment(request, attachmentTo));
            }
        }
    }
    return result;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:41,代码来源:AttachmentResourceHandler.java

示例7: getHashtable

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
public Hashtable getHashtable(HttpServletRequest request)
    throws FileUploadException, IOException {
	Hashtable ht = new Hashtable();
	DiskFileUpload upload = new DiskFileUpload();
	List fileItems = upload.parseRequest(request);
	Iterator iter = fileItems.iterator();
	while (iter.hasNext()) {
	    FileItem item = (FileItem) iter.next();
	    if (item.isFormField()) {
	        ht.put(item.getFieldName(), item.getString());
	    } else {
	        if (item.getName().equals("")) {
	            //ht.put(item.getFieldName(), null);
	        } else if (item.getSize() == 0) {
	            //ht.put(item.getFieldName(), null);
	        } else {
	            ht.put(item.getFieldName(), item.getInputStream());
	        }
	    }
	}
	return ht;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:23,代码来源:PartnershipPageletAdaptor.java

示例8: handleRequestInternal

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.POST)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {

    String username = securityService.getCurrentUsername(request);

    // Check that we have a file upload request.
    if (!ServletFileUpload.isMultipartContent(request)) {
        throw new Exception("Illegal request.");
    }

    Map<String, Object> map = new HashMap<String, Object>();
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List<?> items = upload.parseRequest(request);

    // Look for file items.
    for (Object o : items) {
        FileItem item = (FileItem) o;

        if (!item.isFormField()) {
            String fileName = item.getName();
            byte[] data = item.get();

            if (StringUtils.isNotBlank(fileName) && data.length > 0) {
                createAvatar(fileName, data, username, map);
            } else {
                map.put("error", new Exception("Missing file."));
                LOG.warn("Failed to upload personal image. No file specified.");
            }
            break;
        }
    }

    map.put("username", username);
    map.put("avatar", settingsService.getCustomAvatar(username));
    return new ModelAndView("avatarUploadResult","model",map);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:38,代码来源:AvatarUploadController.java

示例9: doGet

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        try
        {
            DiskFileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            upload.setHeaderEncoding("UTF-8");
            if (!ServletFileUpload.isMultipartContent(request))
            {
                return;
            }
            this.fileList = upload.parseRequest(request);
//            System.out.println(fileList.size());
            for (FileItem item : fileList)
            {
                if (item.isFormField())
                {
                    String value = item.getString("UTF-8");
//                  System.out.print(value);
                    names.add(value);
                } else
                {
                    String filename = item.getName();
                    if (filename == null) continue;
                    File newFile = new File(filename);
//            		System.out.println(newFile.getCanonicalPath());
//            		item.write(newFile);
                    this.names.add(newFile.getAbsolutePath().toString());
                    saveFile(item);
                }
            }

        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }
 
开发者ID:dbiir,项目名称:rainbow,代码行数:38,代码来源:UploadHandleServlet.java

示例10: multipartHandler

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
@Override
public Map<String, String[]> multipartHandler() throws Exception {
	multipart = new Multipart();
	DiskFileItemFactory disk = new DiskFileItemFactory();
	ServletFileUpload servletFileUpload = new ServletFileUpload(disk);
	List<FileItem> items = servletFileUpload.parseRequest(wrapper.httpRequest());

	Map<String, String[]> params = new HashMap<>();

	for (FileItem fileItem : items) {
		if (fileItem.isFormField()) {
			String fieldName = fileItem.getFieldName();
			String fieldVal = fileItem.getString("UTF-8");
			String[] param = params.get(fieldName);
			
			if (param != null) {
				String[] newArray = new String[param.length + 1];
				System.arraycopy(param, 0, newArray, 0, param.length);
				newArray[param.length] = fieldVal;
				param = newArray;
			} else {
				param = new String[]{fieldVal};
			}
			params.put(fieldName, param);
		} 
		else {
			multipart.addFiles(fileItem);
		}
	}
	return params;
}
 
开发者ID:NymphWeb,项目名称:nymph,代码行数:32,代码来源:ResolverUrlImpl.java

示例11: processFileItems

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
private void processFileItems(List<FileItem> fileItems) throws Exception {
    if (isExists(fileItems)) {
        for (FileItem item : fileItems) {
            if (!item.isFormField()) {
                saveFileItem(item);
            }
        }
    }
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:10,代码来源:FileUploadServlet.java

示例12: read

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
@Override
public MultiValueMap<String, ?> read(Class<? extends MultiValueMap<String, ?>> clazz,
        HttpServletRequest request) throws IOException, HttpMessageNotReadableException {
    
    @SuppressWarnings("unchecked")
    MultiValueMap<String, Object> result = ServletUtils.extractUrlParams(request);
    
    if (ServletFileUpload.isMultipartContent(request)) {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload fileUpload = new ServletFileUpload(factory);
        try {
            List<FileItem> fileItems = fileUpload.parseRequest(request);
            for (FileItem fileItem : fileItems) {
                if (fileItem.isFormField()) {
                    result.add(fileItem.getFieldName(), fileItem.getString(this.charset.name()));
                } else {
                    if (isImageMediaType(fileItem.getContentType())) {
                        result.add(fileItem.getFieldName(), new CommonsImageMultipartFile(fileItem));
                    } else {
                        result.add(fileItem.getFieldName(), new CommonsMultipartFile(fileItem));
                    }
                }
            }
        } catch (FileUploadException e) {
            logger.error("File upload failed", e);
        }
    }
    return result;
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:30,代码来源:MultipartFormHttpMessageReader.java

示例13: receiveFile

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked" })
	private void receiveFile(HttpServletRequest request, OnFileReceiveListener listener) throws Exception{
		
		DiskFileItemFactory factory = new DiskFileItemFactory();

		// 临时文件夹路径
		String repositoryPath = ConfigManager.getManager().FILE_TEMP_PATH;
		// 设定临时文件夹为repositoryPath
		File fileTempFolder = new File(repositoryPath);
		if(!fileTempFolder.exists())fileTempFolder.mkdirs();
		factory.setRepository(fileTempFolder);

		// 设定上传文件的阈值,如果上传文件大于1M,就可能在repository
		// 所代 表的文件夹中产生临时文件,否则直接在内存中进行处理
		factory.setSizeThreshold(1024 * 1024);

		// 创建一个ServletFileUpload对象
		ServletFileUpload uploader = new ServletFileUpload(factory);

			// 调用uploader中的parseRequest方法,可以获得请求中的相关内容,
			// 即一个FileItem类型的ArrayList。FileItem是在
			// org.apache.commons.fileupload中定义的,它可以代表一个文件,
			// 也可以代表一个普通的form field
			ArrayList<FileItem> list = (ArrayList<FileItem>) uploader.parseRequest(request);
			for (FileItem fileItem : list){
				if (!fileItem.isFormField()){ // 如果是文件
					String fileName = fileItem.getName() + UUID.randomUUID();
					// 将其中包含的内容写到指定目录下名为fileName的文件中
					File file = new File(ConfigManager.getManager().FILE_SAVE_PATH + File.separator + fileName);
					file.createNewFile();
//					System.out.println(file.getPath());
					fileItem.write(file);
					
					listener.onFinished(MD5.getMD5CodeByFile(file),fileName,file.length());
					break;//一次请求只接受一个文件
				}
			}
	}
 
开发者ID:landriesnidis,项目名称:PCloud_Server_v3,代码行数:39,代码来源:UploadAction.java

示例14: getParameterMapForMultipart

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
/**
 * File Uploadがある場合のパラメータ解析を行います。
 * @param req HTTPリクエスト。
 * @return パラメータ解析結果。
 * @throws Exception 例外。
 */
private Map<String, Object> getParameterMapForMultipart(final HttpServletRequest req) throws Exception {
	Map<String, Object> map = new HashMap<String, Object>();
	DiskFileItemFactory factory = new DiskFileItemFactory();
	factory.setRepository(new File(tempDir)); //一時的に保存する際のディレクトリ
	ServletFileUpload upload = new ServletFileUpload(factory);
	upload.setHeaderEncoding(encoding);
	@SuppressWarnings("unchecked")
	List<FileItem> list = upload.parseRequest(req);
	for (FileItem item : list) {
		String key = item.getFieldName();
		if (key != null) {
			if (item.isFormField()) {
				String value = item.getString(encoding);
				this.addParamMap(map, key, value);
			} else {
				String filename = item.getName();
				if (StringUtil.isBlank(filename)) {
					map.put(key, null);
				} else {
					map.put(key, item);
				}
			}
		}
	}
	return map;
}
 
开发者ID:takayanagi2087,项目名称:dataforms,代码行数:33,代码来源:DataFormsServlet.java

示例15: doPost

import org.apache.commons.fileupload.FileItem; //导入方法依赖的package包/类
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    try {
        List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
        String fileName = null;
        String filePath = null;
        String path = null;
        InputStream fileContent = null;
        for (FileItem item : items) {
            if (!item.isFormField()) {
                fileContent = item.getInputStream();
                fileName = FilenameUtils.getName(item.getName());
            }else if (item.isFormField() && item.getFieldName() != null
                    && item.getFieldName().equals("filePath")){
                path = item.getString();
            }
        }
        filePath = path + File.separator + fileName;
        OutputStream dest = new FileOutputStream(new
                File(filePath));
        int read = 0;
        byte[] bytes = new byte[1024];
        while ((read = fileContent.read(bytes)) != -1) {
            dest.write(bytes, 0, read);
        }
        fileContent.close();
        dest.close();

    } catch (FileUploadException e) {
        e.printStackTrace();
        throw new ServletException("Cannot parse multipart request.", e);
    }
    index(request, response);
}
 
开发者ID:fredcampos,项目名称:shellbomb,代码行数:35,代码来源:UploadServlet.java


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