简体   繁体   中英

How to get the file name when using Part to upload files with JSF?

I'm using the below code snippet to upload a file using JSF

 private Part uploadedFile;
 public Part getUploadedFile() {
    return uploadedFile;
}
public void setUploadedFile(Part uploadedFile) {
    this.uploadedFile = uploadedFile;
}
public void processFileUpload()
{


if(!(uploadedFile==null))
{
fileName = uploadedFile.getName();
System.out.println(fileName);
fileSize = uploadedFile.getSize();
fileContentType = uploadedFile.getContentType();

}
else { System.out.println("null");

My jsp code snippets is shown below

<h:form enctype = "multipart/form-data">

<h:outputLabel value="Select File:" style="color:white"/>
<h:inputFile id="fileUpload" label="File to upload" style="color:white"
value="#{actionBeanWorld.uploadedFile}" size="60" />

 <h:commandButton type = "submit" value = "Upload"
 action = "#{actionBeanWorld.processFileUpload}">
 </h:commandButton>

The filename generated using uploadedFile.getName() generates only the Part name j_id_jsp_903082837_1:fileUpload but I was wondering if there was a way to get the filename I actually uploaded? I already tried using uploadedFile.getSubmittedFileName(); and it threw a java.lang.AbstractMethod error. Please help!

AbstractMethodError thrown by javax.servlet.http.Part.getSubmittedFileName()

MyFaces Core Affects Version/s: 2.2.6, 2.2.8

Please provide full details of the JSF version , Implementation , Server on which you are testing you code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM