title: Read uploaded file in struts2
body: <p>How to read uploaded file in struts2?</p>
  
  <p>I am developing a web app and i have some issue when i upload file : I can upload type of file i needed 
   like :  i can  upload and read image   but i can't  read others file when i upload him</p>
  
  <p>here is my jsp file :</p>
  
  <pre><code>&lt;s:form action="fileUpload" method="post" enctype="multipart/form-data"&gt;
      &lt;s:file name="toBeUploaded" label="Choose file to upload" /&gt;
      &lt;s:submit value="upload" align="center"/&gt;
  &lt;/s:form&gt;
  </code></pre>
  
  <p>Action Class :</p>
  
  <pre><code>public class FileUploadAction extends ActionSupport implements ServletRequestAware {
  
      public File toBeUploaded;
      public String toBeUploadedFileName;
      public String toBeUploadedContentType;
      private HttpServletRequest servletRequest;
  
      public String execute() {
  
           String filePath =             servletRequest.getSession().getServletContext().getRealPath("/");
           System.out.println("Server path:" + filePath);
           File fileToCreate = new File(filePath, this.toBeUploadedFileName);
  
           try {
              FileUtils.copyFile(this.toBeUploaded, fileToCreate);
              FileUtils.copyFile(toBeUploaded, fileToCreate);
          } catch (IOException e) {
              // TODO Auto-generated catch block
              addActionError(e.getMessage());
          }
          return SUCCESS;
      } + getters/setters
  
  
  
  
  &lt;action name="fileUpload" class="com.ged.control.FileUploadAction"&gt;
  &lt;interceptor-ref name="basicStack"/&gt;
   &lt;interceptor-ref name="fileUpload"&gt;
  &lt;param name="maximumSize"&gt;9999999999&lt;/param&gt;
  &lt;param name="allowedTypes"&gt;image/gif,image/jpeg,image/png,application/msword,
   application/mspowerpoint,text/doc,text/plain,application/pdf,application/ms-excel,application/xml,application/powerpoint,audio/mpeg3,audio/x-mpeg-3,video/mpeg,video/x-mpeg,audio/wav,application/x-mspowerpoint,application/vnd.ms-excel,video/avi&lt;/param&gt;
              &lt;/interceptor-ref&gt;
  
              &lt;interceptor-ref name="validation"/&gt;
              &lt;interceptor-ref name="workflow"/&gt;
              &lt;interceptor-ref name="defaultStack"&gt;&lt;/interceptor-ref&gt;
  
              &lt;result name="success"&gt;/uploadSucceed.jsp&lt;/result&gt;
              &lt;result name="input"&gt;/fileUpload.jsp&lt;/result&gt;
          &lt;/action&gt;
  </code></pre>
  
  <p>result page :</p>
  
  <pre><code>&lt;article class="module width_full"&gt;
                  &lt;header&gt;&lt;h3&gt;Post New section&lt;/h3&gt;&lt;/header&gt;
                  File Name : &lt;s:property value="toBeUploadedFileName"&gt;&lt;/s:property&gt;
                      &lt;br/&gt;
                  Content type: &lt;s:property value="toBeUploadedContentType" &gt;&lt;/s:property&gt;
                      &lt;br/&gt;
                  User file :&lt;s:property value="toBeUploaded"&gt;&lt;/s:property&gt;
                      &lt;br/&gt;
                  Uploaded file: 
                      &lt;br/&gt;
                      &lt;img src="&lt;s:property value="toBeUploadedFileName"/&gt;" &gt;&lt;/img&gt;
  
          &lt;/article&gt;
  </code></pre>