title: Uploading image in struts2
body: <p>I have problem when upload image in Struts2.</p>
  
  <p>I am trying to upload an image from jsp page to action class in struts2</p>
  
  <p>My code is successfully run but executes up to System.out.println("2") and the image is not copied to the specified location.</p>
  
  <p>Please help me to solve this problem</p>
  
  <p>My Action class is below:</p>
  
  <pre><code>import java.io.File;
  import java.util.List;
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts2.ServletActionContext;
  import org.apache.tomcat.util.http.fileupload.FileItem;
  import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
  import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;
  import com.opensymphony.xwork2.ActionSupport;
  
  
  public class upload extends ActionSupport  {
  
  public String execute()throws Exception
  {
      try{
  
      HttpServletRequest request = ServletActionContext.getRequest();
  
      System.out.println("1");
      List&lt;FileItem&gt; items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
  
      System.out.println("2");
      for (FileItem item : items)
      {
          System.out.println("3");
              if (!item.isFormField()){
              String fieldname = item.getFieldName();
              System.out.println(fieldname);
  
              System.out.println("4");
              File file = new File("F:/www/test/Rohit/workspace_Rohit/uploadWithStruts2/WebContent/uploadimage","hi.jpg");        
              item.write(file);
           }
      }
  
      }
      catch (Exception e) {
      System.out.println(e);
      }
  
      return SUCCESS;
      }
  
  }
  </code></pre>
  
  <p>My jsp page is:</p>
  
  <pre><code>&lt;form action="test.action" method="post" enctype="multipart/form-data"&gt;
                  &lt;input type="file" name="image"&gt;
                  &lt;input type="submit" value="upload"/&gt;
  &lt;/form&gt;
  </code></pre>