title: Struts 2 file upload : File object being null
body: <p>I am trying to use Struts 2 file upload but it seems to me that its not working. Below is my code.</p>
  
  <p><code>UploadAction.java</code>:</p>
  
  <pre><code>public class UploadAction extends ActionSupport{
  
      private File file;
      private String orgFileName;
      private String orgContentType;
  
      public void setUpload(File file){
          this.file=file;
      }
  
      public void setUploadContentType(String contentType){
          this.orgContentType=contentType;
      }
      public void setUploadFileName(String fileName){
          this.orgFileName=fileName;
      }
  
      @Override
      public String execute(){
          if(file==null)
          {
              System.out.println("No file....");
          }
          System.out.println(orgContentType);
          System.out.println(orgFileName);
          return SUCCESS;
      }
  
  
  }
  </code></pre>
  
  <p><code>struts.xml</code>:</p>
  
  <pre><code>    &lt;constant name="struts.multipart.maxSize" value="20971520" /&gt;
      &lt;constant name="struts2.multipart.saveDir" value="C:/users/sabertooth/desktop/upload" /&gt;
      &lt;include file="example.xml"/&gt;
  
      &lt;!-- Configuration for the default package. --&gt;
      &lt;package name="default" extends="struts-default"&gt;
          &lt;action name="upload" class="UploadAction"&gt;
  
              &lt;result name="success"&gt;/example/HelloWorld.jsp&lt;/result&gt;
          &lt;/action&gt;
      &lt;/package&gt;
  </code></pre>
  
  <p>I am also trying to set struts2.multipart.saveDir property as you can see above but when I read the server logs I see this line</p>
  
  <pre><code>unable to find `struts.multipart.saveDir` defaulting to `javax.servlet.dir`
  </code></pre>
  
  <p>Also the file object is null as no file... gets printed out on console.
  I can't figure out what is wrong here.</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p><code>fileupload.jsp</code>:</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;upload file below&lt;/h1&gt;
          &lt;s:form action="upload" method="post" enctype="multipart/form-data"&gt;
              &lt;input type="file" name="file" id="uploadfile" /&gt;
              &lt;input type="submit" id="submit" /&gt;
          &lt;/s:form&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>