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


Java UploadedFile类代码示例

本文整理汇总了Java中com.ibm.xsp.http.UploadedFile的典型用法代码示例。如果您正苦于以下问题:Java UploadedFile类的具体用法?Java UploadedFile怎么用?Java UploadedFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: uploadLocalFile

import com.ibm.xsp.http.UploadedFile; //导入依赖的package包/类
public void uploadLocalFile() {

	    FacesContext facesContext = FacesContext.getCurrentInstance();
	    ExternalContext externalContext = facesContext.getExternalContext();

	    HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();

	    String fileUploadID = ExtLibUtil.getClientId(facesContext, facesContext.getViewRoot(), "fileUpload1", false);
	    
	    UploadedFile uploadedFile = ((UploadedFile) request.getParameterMap().get(fileUploadID));

	    if (uploadedFile == null) {
	        facesContext.addMessage("messages1", new FacesMessage(FacesMessage.SEVERITY_ERROR, "No file uploaded. Use the file upload button to upload a file.", ""));
	        return;
	    }
    
	    java.io.File file = uploadedFile.getServerFile();
	    String contentType=uploadedFile.getContentType();
	    String fileName = uploadedFile.getClientFileName();

	    String projectId=DevelopiUtils.strRight((String)ExtLibUtil.getViewScope().get("selectedProject"), "|");
	    
	    try {

	    	File newFile=uploadFile(projectId, fileName, new FileInputStream(file), contentType);
	    	
	    	if(newFile==null) {
		        facesContext.addMessage("messages1", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error detected during upload. Check logs...", ""));
		        return;
	    	}
	    	
	    } catch (Exception e) {
	    	e.printStackTrace();
	        facesContext.addMessage("messages1", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error in uploaded file.", ""));
	        return;
	    }

	    facesContext.addMessage("messages1", new FacesMessage(FacesMessage.SEVERITY_INFO, "File successfully uploaded", ""));
	}
 
开发者ID:sbasegmez,项目名称:ic14demos,代码行数:40,代码来源:BaseCampService.java


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