本文整理汇总了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", ""));
}