218 total views, 6 views today

JSF InputFIle – FileUpload Example

 

The JSF InputFile component is used to upload files from client machine. The uploaded files will be saved in the server. Below is the h:inputFIle component and its corresponding HTML tag

 

JSF => <h:inputFile value=”#{fileupload.uploadedFile}” />

HTML => <input type=”filename=”j_idt4” />

 

The below example explains about JSF File Upload.

 

JSF h:inputFile Example

 

Below is the index.jsf Page; An h:inputFile component inside Form. Also note I mentioned an mandatory HTML attribute for file uploads enctype=”multipart/form-data”.

 

 

 

Below is the Backing bean class. I bound the InputFile field with the part attribute. The Part class is present under serlet-api.jar file which presents under the tomcat\lib directory. Also notice, I saved the uploaded file to my c:\ drive.

 

 

 

This is how the above JSF page look likes in the browser. I uploaded a file Notice.txt and it saved in the folder c:\\file.

JSF_FileUpload_Example JSF InputFile File upload Example

 

Download the Source Code:

govindan JSF InputFile File upload Example
Connect me

Govind

Thank you for visiting my personal blog. Myself Govindan, Software Developer by profession since 2006 and hence I started this blog early in 2016 and ever since I've been writing about technologies experienced and learnings of everyday life.

The views expressed on this blog are my personal views and do not necessarily reflect the views of my employer.

Please feeling free to reach me on any comments and feedbacks you have. Would be more than glad to listen and reply 🙂
govindan JSF InputFile File upload Example
Connect me
By | 2017-11-22T03:22:54+00:00 November 22nd, 2017|Categories: JSF|Tags: , , , |0 Comments
Like us on Facebook.
Connect!