title: JSF 2.0 file upload - walkthrough?
body: <p>I have looked around for a while looking for a complete guide for this. I've been working with JSF like 2 days now and am trying to make a page that will upload a pdf file to a server, putting its file path into a database along with other user-inputted text fields. </p>
  
  <p>This is my form (so far)</p>
  
  <pre><code>&lt;h:form enctype="multipart/form-data"&gt;
          &lt;h:outputText value="Name: " /&gt;
          &lt;h:inputText id="name" size="40" value="#{resumeBean.name}" required="true"/&gt; &lt;br/&gt;
          &lt;h:outputText value="Position Sought: "/&gt;
          &lt;h:inputText id="position" size="40" value="#{resumeBean.position}" required="true"/&gt; &lt;br/&gt;
          &lt;h:outputText value="Date: " /&gt;
          &lt;h:inputText id="date" size="40" value="#{resumeBean.date}" required="true" /&gt; &lt;br/&gt;
          &lt;h:outputText value="File to upload: " /&gt;
          &lt;t:inputFileUpload value="#{bean.resume}" /&gt; &lt;br/&gt;
          &lt;h:commandButton value="submit" action="#{bean.submit}" /&gt;
          &lt;h:messages /&gt;
      &lt;/h:form&gt;
  </code></pre>
  
  <p>and this bean to handle the file</p>
  
  <pre><code>   package com.example;
  
  import java.io.IOException;
  
  import javax.faces.application.FacesMessage;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.RequestScoped;
  import javax.faces.context.FacesContext;
  
  import org.apache.commons.io.FilenameUtils;
  import org.apache.myfaces.custom.fileupload.UploadedFile;
  
  @ManagedBean
  @RequestScoped
  public class Bean {
  
      private String name, position, date;
      private String fileName;
      private UploadedFile resume;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getPosition() {
          return position;
      }
  
      public void setPosition(String position) {
          this.position = position;
      }
  
      public String getDate() {
          return date;
      }
  
      public void setDate(String date) {
          this.date = date;
      }
  
      public void setResume(UploadedFile resume) {
          this.fileName = resume.getName();
          this.resume = resume;
      }
  
      public UploadedFile getResume() {
          return resume;
      }
  
      public String getFileName() {
          return fileName;
      }
  
      public void submit() throws IOException {
          String fileName = FilenameUtils.getName(resume.getName());
          String contentType = resume.getContentType();
          byte[] bytes = resume.getBytes();
  
          // Now you can save bytes in DB (and also content type?)
  
          FacesContext.getCurrentInstance().addMessage(null, 
              new FacesMessage(String.format("File '%s' of type '%s' successfully uploaded!", fileName, contentType)));
      }
  }
  </code></pre>
  
  <p>web.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app 
      xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      id="timesheet2" version="3.0"&gt;
    &lt;display-name&gt;&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;faces/login.xhtml&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;listener&gt; 
      &lt;listener-class&gt;com.sun.faces.config.ConfigureListener&lt;/listener-class&gt; 
    &lt;/listener&gt; 
    &lt;filter&gt;
      &lt;filter-name&gt;MyFacesExtensionsFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.apache.myfaces.webapp.filter.ExtensionsFilter&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
      &lt;filter-name&gt;MyFacesExtensionsFilter&lt;/filter-name&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>but from here I have no idea how to continue, help please?
  thanks in advance</p>