【发布时间】:2017-03-13 10:52:56
【问题描述】:
我在 Tomcat 服务器上使用了 fileUpload 组件,它确实可以正常工作。当我在 weblogic 服务器上尝试我的应用程序时,文件上传组件不起作用。
<h:form id="fileUpoad" prependId="false" enctype="multipart/form-data">
<!-- File Upload with mode="advanced". multiple files can be uploaded. upload button -->
<h:outputLabel for="fileIdPhoto" value="Hasar fotografini yukleyiniz:"/>
<p:fileUpload id="fileIdPhoto" fileUploadListener="#{fileUploadBean.uploadPhoto}" mode="advanced"
dragDropSupport="false"
multiple="true" update="messages" sizeLimit="10000000" fileLimit="3"
allowTypes="/(\.|\/)(gif|jpe?g|zip)$/"/>
<p:messages id="messages" autoUpdate="true" closable="true"/>
</h:form>
这是我的fileUpload 豆:
@ManagedBean(name = "fileUploadBean")
@RequestScoped
public class fileUpload {
FileUploadEvent e;
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String uploadPhoto() throws IOException {
System.out.println("resim kaydetme metoduna girildi");
UploadedFile uploadedPhoto = e.getFile();
String filePath = "c:/temp/kk";
byte[] bytes = null;
if (null != uploadedPhoto) {
bytes = uploadedPhoto.getContents();
String filename = FilenameUtils.getName(uploadedPhoto.getFileName());
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(filePath + filename)));
stream.write(bytes);
stream.close();
}
System.out.println("resim kaydettim cikiyorum");
FacesContext.getCurrentInstance().addMessage("messages", new FacesMessage(FacesMessage.SEVERITY_INFO, "(File Name " + uploadedPhoto.getFileName() + " with size " + uploadedPhoto.getSize() + ") Basarili bir sekilde kaydedildi", ""));
return null;
}
}
当我点击“上传”时,我的图片没有保存。这是我的 weblogic 服务器错误:
2016 年 10 月 31 日上午 7:54:49 com.sun.faces.context.ExternalContextImpl getMimeType 警告:JSF1091:找不到文件的 mime 类型 /denemexhtml.xhtml。要解决此问题,请将 mime 类型映射添加到 应用程序 web.xml。 2016 年 10 月 31 日上午 7 点 54 分 49 秒 com.sun.faces.context.ExternalContextImpl getMimeType 警告: JSF1091:找不到文件 /denemexhtml.xhtml 的 mime 类型。到 解决此问题,将 mime 类型映射添加到应用程序 web.xml。
【问题讨论】:
-
请显示您的 FileUploadBean 的代码以及您遇到的错误/异常的描述。
-
而且“没有工作”是含糊的。请调查更多
-
阅读这篇文章 stackoverflow.com/questions/39486157/… 并按照相同的步骤进行操作
-
当我点击“上传”时,出现错误。这是错误:javax.el.MethodNotFoundException 错误
-
那就先找到那个错误的原因。许多关于 Stackoverflow 中特定错误的帖子
标签: java jsf file-upload primefaces