Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed missing class declaration according to comment.

...

The fileUpload interceptor will use setter injection to insert the uploaded file and related data into your Action class. For a form field named upload you would provide the three setter methods shown in the following example:

Example Action class:

Code Block
langjava

package com.example;

   import java.io.File;
   import com.opensymphony.xwork2.ActionSupport;

   public class UploadAction extends ActionSupport {
      private File file;
      private String contentType;
      private String filename;

      public void setUpload(File file) {
         this.file = file;
      }

      public void setUploadContentType(String contentType) {
         this.contentType = contentType;
      }

      public void setUploadFileName(String filename) {
         this.filename = filename;
      }

      public String execute() {
         //...
         return SUCCESS;
      }
 }
Wiki Markup
{snippet:id=example-action|lang=java|javadoc=true|url=org.apache.struts2.interceptor.FileUploadInterceptor}

The purpose of each one of these methods is described in the table below. Notice that if you have multiple file form elements with different names you would be required to have another corresponding set of these methods for each file uploaded.

...